Bitwise and logical AND / OR in terms of hexadecimal result

therefore, if I have x = 0x01and y = 0xff, and I do x & y, I would receive 0x01. If I do x && y, I get it anyway 0x01, but the computer just says that it’s true if its nothing but 0x00? My question is, are the bits the same after the operation, regardless of the bit-wise or logical AND / OR, but does the computer simply interpret the end result differently? In other words, are the hexadecimal values ​​of the result and and && (similar to | and ||) the same?

edit: talk about C here

0
source share
2 answers

The answer depends on the exact language used.

In some weakly typed languages (eg, Perl, JavaScript) a && bwill be assessed by the actual value b, if both aand bare "true" or aotherwise.

In C and C ++, the operator &&will simply return 0 or 1, i.e. equivalent int trueor false.

In Java and C #, it is not even legal to deliver intto &&- operands should already be logical.

I don’t know any language from the top of my head, where a && b == a & bfor all the valid values ​​of aand b.

+1
source

# -: & & , .

a && b true, a b . a b AND.

0

Source: https://habr.com/ru/post/1648869/


All Articles