Often the question is asked "What is the notation for 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: * In CeeLanguage/CeePlusPlus; any integer literal starting with 0x is hex, anything starting with 0 is octal. Decimal integer literals must start with 1-9; fortunately the number "0" is the same whether decimal or hex. The lexemes for floating point numbers (things with a decimal point in them) are always decimal in C/C++. * '$' has been used as a hex prefix for many years (AppleTwo assembly, many ForthLanguage implementations) ''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?" * Dunno; it would be useful, especially given the low-level bit-frobbing that C/C++ are frequently used for. ** Binary literals (0b1001010) are added to many embedded C compilers, such as for PIC microcontrollers, since you do a lot bit-level I/O on these devices. 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. ' Where is the number of bits in the value, written decimal, is the radix expressed as one of h, d, o, or b, and is the actual number, written in base . 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