This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Coding a binary data

Hello,

I just want to code a binary data in C.
I mean hera representation is "0x5F", the decimal representation is simply "156" but what is the decimal representation.
I tried 0b010010101 but it doesn't work

Many thanks

Sébastien

Parents
  • #define LongToBin(n) \ 
    (\ 
    ((n >> 21) & 0x80) | \ 
    ((n >> 18) & 0x40) | \ 
    ((n >> 15) & 0x20) | \ 
    ((n >> 12) & 0x10) | \ 
    ((n >>  9) & 0x08) | \ 
    ((n >>  6) & 0x04) | \ 
    ((n >>  3) & 0x02) | \ 
    ((n      ) & 0x01)   \ 
    )
    
    #define Bin(n) LongToBin(0x##n##l)
    
    Then when you write Bin(00010001), you will get a 0x11.

Reply
  • #define LongToBin(n) \ 
    (\ 
    ((n >> 21) & 0x80) | \ 
    ((n >> 18) & 0x40) | \ 
    ((n >> 15) & 0x20) | \ 
    ((n >> 12) & 0x10) | \ 
    ((n >>  9) & 0x08) | \ 
    ((n >>  6) & 0x04) | \ 
    ((n >>  3) & 0x02) | \ 
    ((n      ) & 0x01)   \ 
    )
    
    #define Bin(n) LongToBin(0x##n##l)
    
    Then when you write Bin(00010001), you will get a 0x11.

Children