Numeric Notations

Often the question is asked "What is the notation for <octal/hex/binary/base-ten> numbers in software"?

There are sometimes incomplete or conflicting notations. Please add any other forms. Reformatted as a table for easier comparison. -sf

NOTE: not all forms listed below are actually syntactically correct; rather, the forms would be correct if taken to their extremes and actually implemented.

                                     Intel/                6502/68K
          Raw Form   CeeLanguage      Zilog     Ada/VHDL  assembler  RexxLanguage       Verilog

Binary 10011101 0b10011101 10011101B 2#10011101 %10011101 '10011101'b 8'b10011101 Octal 5 05 05O 8#5 @5 '101'b 4'o5 Hex 1F 0x1F 01FH 16#1F $1F '1F'x 8'h1F Decimal 27 27 27 27 27 27 27

Footnotes: There are conflicts. For instance, is "1001" binary or base-ten? Lexical analysis will not be able to resolve the difference, although a LALR syntax analyzer might - with proper context

Why is there no nice notation for binary. . . or "why doesn't C/C++ recognize 1001B as binary?"

Some languages have an arbitrary-radix format.

Verilog, a hardware description language, extends number to include "don't care's" and "high-impedance" values as well as traditional numbers.

 <length>'<radix><digits>

Where <length> is the number of bits in the value, written decimal, <radix> is the radix expressed as one of h, d, o, or b, and <digits> is the actual number, written in base <radix>. 0-9 are themselves, a-f represent 10 through 15, z represents hi-impedance, x represents "don't care". Some examples are
    10'd1023
    3'b1zz
    3'b101
    3'o7
    32'hdead_beef

Other languages have similar constructs.


shouldn't the same example value (e.g. 42 2A 52 101010) be used for all bases?

I interpreted the original idea behind this page as demonstrating syntax, not arithmetic equality. In fact, I used the same numbers which were originally posted by the original author. --SamuelFalvo?


See also: NumberTypes


CategoryMath


EditText of this page (last edited April 30, 2008) or FindPage with title or text search