Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Number Bases

Input literals

Any numeric literal can be written in hex, binary, or octal:

PrefixBaseExampleValue
0x / 0XHexadecimal0xFF255
0b / 0BBinary0b101010
0o / 0OOctal0o1715

Mixed-base expressions work naturally:

0xFF + 0b1010        →  265
0x10 + 0o10 + 0b10   →   26

Display base

By default results are shown in decimal. Switch with a command (session-local):

CommandEffect
decDecimal (default)
hexHexadecimal
binBinary
octOctal

The display base persists until changed and affects both the prompt and all results. To make a non-decimal base the default across all sessions, set it in config.toml.

[ 0 ]: 255
[ 255 ]: hex
[ 0xFF ]: + 1
[ 0x100 ]: dec
[ 256 ]:

Inline base suffix

Write a base keyword after an expression to evaluate it and switch the display in one step:

[ 0 ]: 0xFF + 0b1010 hex
[ 0x109 ]:

base — show all representations

[ 10 ]: base
2  - 0b1010
8  - 0o12
10 - 10
16 - 0xA

base can also be used as an inline suffix to show one result in all four bases without changing the active display base:

[ 0 ]: 255 base
2  - 0b11111111
8  - 0o377
10 - 255
16 - 0xFF
[ 255 ]:

Mixed-base display conversion

When the active display base is non-decimal and the input contains literals in other bases, the expression is automatically reprinted with all literals converted to the active base before the result is shown:

[ 0b110 ]: 2 + 0b110 + 0xa
0b10 + 0b110 + 0b1010
[ 0b10010 ]: