So, binary is just base 2, right? 1s and 0s. But why, when you convert from dec to bin, on Google for example, does it also have an (x)b in front of the actual number? What does the, for example, 0b __ mean?
Asked
Active
Viewed 7,813 times
1 Answers
15
The notation 0b in front of a number is just an indicator that what follows is represented in binary. That way, if you see something like 1001, you know it's the number "one thousand one" rather than nine written out in binary.
More generally, the prefix 0b usually means "binary," the prefix 0 usually means "octal," and the prefix 0x usually means "hexadecimal."
Hope this helps!

templatetypedef
- 362,284
- 104
- 897
- 1,065
-
okay, i get it. so there would be no case where it would be like, 1b instead of 0b, right? if so, why not just b? – Aristides Jul 08 '13 at 21:26
-
3@Aristides- I think the reason is historical. C used the 0 prefix and 0x prefix for octal and hexadecimal so that when the scanner encountered a token starting with 0, it knew it was definitely a number (since identifiers can't start with numbers). For example, `b100101` might be interpreted as a variable name rather than an integer literal. The convention has persisted since then. – templatetypedef Jul 08 '13 at 23:27
-
ohh so if the num before the b was like 3, it could be an object or something? – Aristides Jul 08 '13 at 23:53
-
@Aristides- Not quite - it's more that if there isn't a number before the `b` at all, then it looks like a variable name. The fact that the number is always 0 is purely historical. – templatetypedef Jul 08 '13 at 23:56