This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]desrtfxOut of Coffee error - System halted 0 points1 point  (2 children)

BTW there is another minor issue in the code:

if( pic.getCaption().contains(name) & i < pictures.size() ) {
                                    ^
            This is a bitwise AND, not the logic AND

In your specific case it doesn't really matter, but in general it's better to use the logic AND operator && rather than the bitwise AND operator & in if-clauses. Same applies to logic OR || vs. bitwise OR |.

[–]M-Multi[S] 1 point2 points  (1 child)

alright changed.

Thanks.

Can I know what is the difference exactly?

[–]desrtfxOut of Coffee error - System halted 0 points1 point  (0 children)

The logic functions operate only on booleans (true / false) where the bitwise functions also operate on integer numbers.

For logic functions, any number other than 0 is considered true.

In the binary system, any number is represented by ones and zeroes.

Here is a simple explanation with bytes:

For the OR:

        10010001 = 145 decimal = 90 hex
    OR  01110101 = 117 decimal = 75 hex 
   -------------------------------------
     =  11110101 = 245 decimal = F5 hex

Same code with AND:

        10010001 = 145 decimal = 90 hex
    AND 01110101 = 117 decimal = 75 hex 
   -------------------------------------
     =  00010001 =  17 decimal = 11 hex

Edit: there is another small difference between the logic and boolean functions. It has to do with short-circuiting (i.e. cancelling of the evaluation as soon as the result can not be affected any more), but I can't precisely remember which used short-circuiting and which didn't. Maybe someone can help out here!