简体   繁体   English

如何将十六进制转换为二进制

[英]How to convert hexadecimal to binary

What's the representation of 0x2b in binary? 0x2b的二进制表示是什么? And how to convert it ? 以及如何转换呢? Im a little confused about b . 我对b有些困惑。

char a = 0x2b;

The 0x part means the following number is in hexadecimal notation. 0x部分表示以下数字以十六进制表示。

Since in hex, 0x10 == 16 and 0xb = 11 , we have: 由于十六进制为0x10 == 160xb = 11 ,我们有:

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

So 0x2B is 43 in decimal (the system we commonly use), and that's 所以0x2B是十进制的43 (我们通常使用的系统),这就是

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. 为了明确起见,无论您使用什么符号(十进制或十六进制)在C中声明/覆盖变量,结果都是相同的。

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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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