Can I use a binary literal in C or C++?

前端 未结 19 2447
梦如初夏
梦如初夏 2020-11-22 07:40

I need to work with a binary number.

I tried writing:

const x = 00010000;

But it didn\'t work.

I know that I can use an hex

19条回答
  •  -上瘾入骨i
    2020-11-22 08:04

    The "type" of a binary number is the same as any decimal, hex or octal number: int (or even char, short, long long).

    When you assign a constant, you can't assign it with 11011011 (curiously and unfortunately), but you can use hex. Hex is a little easier to mentally translate. Chunk in nibbles (4 bits) and translate to a character in [0-9a-f].

提交回复
热议问题