liveBook · Manning

Binary literal

As explained in Modern C, Third Edition

A binary integer literal is a C23 integer literal written with a 0b or 0B prefix and binary digits.

A binary integer literal is a C23 integer literal written with the prefix 0b or 0B, followed by a sequence containing only 0 and 1 digits. The digits represent a number in base two. section 5.3

A binary value

int mask = 0b1010; /* value: 10 */ int same = 0B1010; /* also value: 10 */ The uppercase B is an alternative spelling of the lowercase b prefix. section 5.3

Key rules:

  • Begin the literal with 0b or 0B. section 5.3
  • Use only binary digits, 0 and 1, after the prefix. section 5.3
  • Treat the literal as an integer constant alongside decimal, octal, and hexadecimal forms. section 5.3

How Modern C, Third Edition covers it

How deep it goes
Defines the prefix, permitted digits, value conversion, and C23 availability without developing typing or suffix rules.
Examples
Uses 0b1010 and 0B1010, both representing the integer value 10.
What you can do after
Evaluate binary integer syntax and translate a small binary literal into its integer value.
How it connects
Connects binary literals with integer literals and decimal, octal, and hexadecimal notation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.