bitwise operators - Use of | in java -
i came across java code in constant has been defined in following way
static final char fm = (char) (constantssystem.double_byte_sep | 0xfe);
what use of |
in code?
the |
bitwise or operator. works follows:
0 | 0 == 0 0 | 1 == 1 1 | 0 == 1 1 | 1 == 1
internally, integer represented sequence of bits. if have, example:
int x = 1 | 2;
this equivalent to:
int x = 0001 | 0010; int x = 0011; int x = 3;
note using 4 bits clarity, int
in java represented 32 bits.
specifically addressing code, if assume, example, value of constantssystem.double_byte_sep
256:
static final char fm = (char) (constantssystem.double_byte_sep | 0xfe); static final char fm = (char) (256 | 254); static final char fm = (char) (0000 0001 0000 0000 | 0000 0000 1111 1110); static final char fm = (char) (0000 0001 1111 1110); static final char fm = (char) (510); static final char fm = 'วพ';
also note way wrote binary numbers not how represent binaries in java. example:
0000 0000 1111 1110
would really:
0b0000000011111110
documentation: bitwise , bit shift operators
Comments
Post a Comment