简体   繁体   中英

How to convert hexadecimal to binary

What's the representation of 0x2b in binary? And how to convert it ? Im a little confused about b .

char a = 0x2b;

The 0x part means the following number is in hexadecimal notation.

Since in hex, 0x10 == 16 and 0xb = 11 , we have:

0x2B = 0x20 + 0xB = 32 + 11 = 43

So 0x2B is 43 in decimal (the system we commonly use), and that's

101011

in binary.

To clarify, no matter what notation you use (decimal or hexadecimal) to declare/overwrite variables in C, the result is the same.

char a = 0x2B;
char b = 43;
if (a == b)
    printf("But of course they're the same!\n");
else
    printf("This should not happen\n");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM