Bases

From C

Jump to: navigation, search

Number bases

This crops up quite frequently, so I'm making a page about it.

The Converting article discusses conversion of numbers to and from strings.

Numeric literals

These are all the same literal number:

   int d, o, h;
   
   d = 47;    /* base 10 */
   o = 057;   /* base 8: the leading zero signifies octal */
   h = 0x2F;  /* base 16: the leading 0x signifies hexadecmial */

The internal representation of the integer is the same in all cases. The number is not stored "as hex". In other words, d, o and h all store identical values.

C does not have binary literals.


Category Language

Personal tools