What is the "0xXXXX" syntax when learning bit manipulation? (where X is a capital alphanumeric character) -


i'm trying learn bit manipulation doing few problems after learning basics , in solutions, seem see format. example:

n = (n & 0xaaaa)>>1 | (n & 0x5555)<<1 

what (specifically 0xaaaa , 0x5555)? , name of syntax or format can up?

thanks

those hexadecimal values. 0xaaaa equivalent 1010101010101010. = 1010 (in binary). therefore 4 a's 4 sequences of binary value.

when combine binary &, bits of n coincide pattern 1010... both bits 1 , keep bits only.

example:

  1110101010101001 & 1010101010101010 ------------------   1010101010101000 

the same goes 0x5555. 5 = 0x0101. idea.

the binary or operator on other hand returns 1 in every place binary numbers have 1, in:

  1010 | 0101 ------   1111 

the bit shift operators ( >> , << ) move each binary digit 1 place on (depending on direction of arrows) , on. hex nicer format visualize bits without having write out every single bit.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -