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

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -