Radix: Difference between revisions
From wikinotes
(Created page with "A number's radix or number's base describes when the next higher digit gets incremented. For example, in a base-10 number system, incrementing beyond <code>9</code> adds an e...") |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
A number's radix or number's base describes when the next higher digit gets incremented. | A number's radix or number's base describes when the next higher digit gets incremented. | ||
For example, in | For example, in the decimal number system (base-10), incrementing beyond <code>9</code> adds an extra digit <code>10</code>.<br> | ||
In the binary number system (base-2), incrementing beyond <code>01</code> increments the higher digit <code>10</code>. | |||
= Documentation = | = Documentation = | ||
Line 11: | Line 12: | ||
|} | |} | ||
</blockquote><!-- Documentation --> | </blockquote><!-- Documentation --> | ||
= Number Bases = | |||
<blockquote> | |||
<syntaxhighlight lang="yaml"> | |||
binary: 2 | |||
octal: 8 | |||
decimal: 10 | |||
hexadecimal: 16 | |||
</syntaxhighlight> | |||
Calculate the maximum possible number with N digits in base B. | |||
<syntaxhighlight lang="bash"> | |||
2**8 == 256 # 8x base-2 digits (0-255) | |||
16**2 == 256 # 2x base-16 digits (0-255) | |||
10**2 == 100 # 2x base-10 digits (0-99) | |||
</syntaxhighlight> | |||
You can take advantage of this to convert from any number base to decimal | |||
<syntaxhighlight lang="bash"> | |||
255 | |||
= 11111111 # in binary | |||
= 1 1 1 1 1 1 1 1 | |||
= 2**7 + 2**6 + 2**5 + 2**4 + 2**3 + 2**2 + 2**1 + 2**0 | |||
= 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 | |||
</syntaxhighlight> | |||
</blockquote><!-- Number Bases --> |
Latest revision as of 00:32, 8 August 2021
A number's radix or number's base describes when the next higher digit gets incremented.
For example, in the decimal number system (base-10), incrementing beyond 9
adds an extra digit 10
.
In the binary number system (base-2), incrementing beyond 01
increments the higher digit 10
.
Documentation
wikipedia https://en.wikipedia.org/wiki/Radix
Number Bases
binary: 2 octal: 8 decimal: 10 hexadecimal: 16Calculate the maximum possible number with N digits in base B.
2**8 == 256 # 8x base-2 digits (0-255) 16**2 == 256 # 2x base-16 digits (0-255) 10**2 == 100 # 2x base-10 digits (0-99)You can take advantage of this to convert from any number base to decimal
255 = 11111111 # in binary = 1 1 1 1 1 1 1 1 = 2**7 + 2**6 + 2**5 + 2**4 + 2**3 + 2**2 + 2**1 + 2**0 = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1