Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

masking out unwanted bits in c

Tags:

c

Given the decimal 71744474 in binary it is 0100010001101011101111011010 what I am trying to extract from this decimal is every seven bits starting from the lower bits. Each of the seven bits are to represent a printable ASCII character which can only have 7 bits. In total I am pulling out four characters. The first character is 1011010 which is Z in ASCII. The next character is w and so on. I am thinking there is a way to mask out the bits I care about some how.

like image 608
foo Avatar asked Dec 16 '22 16:12

foo


1 Answers

Use bitwise operators:

0100010001101011101111011010 & 0000000000000000000001111111 = 1011010

To get the second character, do

0100010001101011101111011010 & 0000000000000011111110000000

and so on..

like image 158
Hari Menon Avatar answered Dec 26 '22 06:12

Hari Menon