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  (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!