http://proglit.com/
numbers
SA BY
1 bit (one of two states)
(a scheme for symbolically and verbally representing quantity) number system (a scheme for symbolically and verbally representing quantity)
unary (the tally system)
Aiwt$e#&!)9?
positional notation (represents arbitrarily large quantities using a finite set of symbols)
(positional notation using 10 symbols) decimal base-10 (positional notation using 10 symbols)
Arabic numerals 0 1 2 3 4 5 6 7 8 9
39 40
9 09 …0000000009
09 10
86999 87000
78 seventy-eight seven eight
Understand that a positional notation system can use any number of symbols as long as it uses at least 2. So you could have a base-3 system, or a base-17 system, or a base-1065 system, or whatever. The decision to use base-10 was really just an arbitrary historical decision, likely made because we have 10 fingers and 10 toes, so it seemed natural to people to use base-10. And in fact, some civilizations used other bases, like the ancient Babylonians used base-12, probably because it fit best with their calendar.
(positional notation using 8 symbols) octal base-8 (positional notation using 8 symbols) So let's look at a positional notation system which uses something other than base-10. The base-8 system goes by the name octal.
0 1 2 3 4 5 6 7 Rather than contriving new symbols, we use the same Arabic numerals as we do in decimal; we just use 8 of them instead of all 10.
07 10 When you have the quantity seven and you wish to express one higher, the '7' cycles back to '0', and the digit to its left cycles to '1', so the quantity we call 'eight' in decimal is written as '1' '0' in octal. While it's very, very tempting to read '1' '0' as the quantity 'ten', it is rather, in octal, the same quantity which we write as '8' in decimal. (After a lifetime of habit, it's really hard to stop yourself from reflexively reading numerals as decimal numbers.)
octal base-8 decimal base-10 1 2 3 4 5 6 7 10 11 12 13 14 1 2 3 4 5 6 9 10 11 12 octal base-8 decimal base-10
octal base-8 decimal base-10 15 16 17 20 21 22 23 24 25 26 27 30 13 14 18 19 20 21 22 23 24 octal base-8 decimal base-10
317777 320000
61 (decimal) 061 (octal)
05673
(positional notation using 16 symbols) hexadecimal hex base-16 (positional notation using 16 symbols)
0 1 2 3 4 5 6 7 8 9 A B C D E F
0F 10
hex base-16 decimal base-10 1 2 3 4 5 6 7 8 9 A B C 1 2 3 4 5 6 7 8 9 11 12 hex base-16 decimal base-10
hex base-16 decimal base-10 D E F 10 11 12 13 14 15 16 17 18 13 14 15 19 20 21 22 23 24 hex base-16 decimal base-10
hex base-16 decimal base-10 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 hex base-16 decimal base-10
ADD BAD BEAD BEE BEEF CAFE DEAD DEAF DEED FAD FEED
0xADD 0xBAD 0xBEAD 0xBEE 0xBEEF 0xCAFE 0xDEAD 0xDEAF 0xDEED 0xFAD 0xFEED
0xA3BFFFFF 0xA3C00000
(positional notation using 2 symbols) binary base-2 (positional notation using 2 symbols)
0 1
01 10
binary base-2 decimal base-10 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1 2 3 4 5 6 7 8 9 10 11 12 binary base-2 decimal base-10
binary base-2 decimal base-10 1101 1110 1111 10000 10001 10010 10011 10100 10101 10110 10111 11000 13 14 15 16 17 18 19 20 21 22 23 24 binary base-2 decimal base-10
101b (binary) 101 (decimal)
10101111b 10110000b
http://proglit.com/
base conversions
36259
(30000) + (6000) + (200) + (50) + (9)
(3 * 10000) + (6 * 1000) + (2 * 100) + (5 * 10) + (9 * 1)
(3 * 104) + (6 * 103) + (2 * 102) + (5 * 101) + (9 * 100)
36259 104 103 102 101 100 10000 1000 100 10 1
octal to decimal
03675
(03000) + (0600) + (070) + (05)
(03 * 01000) + (06 * 0100) + (07 * 010) + (05 * 01)
(03 * 0103) + (06 * 0102) + (07 * 0101) + (05 * 0100)
(3 * 83) + (6 * 82) + (7 * 81) + (5 * 80)
(3 * 512) + (6 * 64) + (7 * 8) + (5 * 1)
(1636) + (384) + (56) + (5)
03675 = 2081
decimal to octal
36256
(3 * 104) + (6 * 103) + (2 * 102) + (5 * 101) + (6 * 100)
(03 * 0124) + (06 * 0123) + (02 * 0122) + (05 * 0121) + (06 * 0120)
(03 * 023420) + (06 * 01750) + (02 * 0144) + (05 * 012) + (06 * 01)
(072460) + (013560) + (0310) + (062) + (06)
36256 = 0106640
hex to decimal
0x36E59
(0x3 * 164) + (0x6 * 163) + (0xE * 162) + (0x5 * 161) + (0x9 * 160)
(3 * 65536) + (6 * 4096) + (14 * 256) + (5 * 16) + (9 * 1)
(196608) + (24576) + (3584) + (80) + (9)
0x36E59 = 224857
binary to decimal
10101b
(1 * 24) + (0 * 23) + (1 * 22) + (0 * 21) + (1 * 20)
(1 * 16) + (0 * 8) + (1 * 4) + (0 * 2) + (1 * 1)
(16) + (0) + (4) + (1)
10101b = 21
10101101b
10101101b 128 32 8 4 1
(128) + (32) + (8) + (4) + (1)
10101101b = 173
22 4 23 8 24 16 25 32 26 64 27 128 28 256 29 512 210 1024 211 2048 212 4096 213 8192 214 16384 215 32768 216 65536 217 131072 218 262144 219 524288 220 1048576
decimal to binary
find biggest fitting power of two subtract it out repeat until left with 0
35872
35872 32768 (215)
1???????????????b
35872 - 32768 = 3104
3104 2048 (211)
10001???????????b
3104 – 2048 = 1056
1056 1024 (210)
100011??????????b
1056 – 1024 = 32
32 32 (25)
10001100001?????b
32 – 32 =
1000110000100000b
why use hex and octal?
octal to binary (and vice versa)
octal base-8 binary base-2 1 2 3 4 5 6 7 000 001 010 011 100 101 110 1 2 3 4 5 6 7 000 001 010 011 100 101 110 111 octal base-8 binary base-2
03673
octal base-8 binary base-2 1 2 3 4 5 6 7 000 001 010 011 100 101 110 1 2 3 4 5 6 7 000 001 010 011 100 101 110 111 octal base-8 binary base-2
03673 011110111011b
1101010110b
001101010110b 01526
hex to binary (and vice versa)
hex base-16 binary base-2 1 2 3 4 5 6 7 8 9 A B C D E F 0000 0001 0010 1 2 3 4 5 6 7 8 9 A B C D E F 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 hex base-16 binary base-2
0x7E9 011111101001b
1100101101b 0x32D
recap Each digit is a coefficient of the number base raised to an increasing power. One technique works for all number base conversions. Shortcut conversions: decimal to binary (sum powers of 2) binary to decimal (subtract out powers of 2) octal and binary (1 octal digit = 3 binary digits) hex and binary (1 hex digit = 4 binary digits) Effectively, hex and octal serve as a compacter way of writing binary.
http://proglit.com/
meaning relies upon agreement
integer (whole number) 5878 0 -87 234
signed integer unsigned integer
0, 1, 2, 3, 4, 5… 0b, 1b, 10b, 11b, 100b, 101b…
n bits = 2n values 1 bit = 2 values 2 bits = 4 values etc…
unsigned value range 1 bit = 0..1 2 bits = 0..3 3 bits = 0..7 etc…
sign bit 00000011 (positive three) 10000011 (negative three)
one’s complement 00000011 (positive three) 11111100 (negative three)
two’s complement 00000011 (positive three) 11111101 (negative three)
two’s complement 11111101 (negative three) 00000011 (positive three)
00000101 (negative three in excess-8) excess-n 00001011 (positive three in excess-8) 00000101 (negative three in excess-8)
00100111 (negative three in excess-42) excess-n 00101101 (positive three in excess-42) 00100111 (negative three in excess-42)
one’s complement: -127 to +127 two’s complement: -128 to +127 8-bit range sign bit: -127 to +127 one’s complement: -127 to +127 two’s complement: -128 to +127
rational numbers 2/5 1/98 7/1 -61/1738
radix-point notation (ratio written as an integer component and a fractional component, separated by a radix point) 3/4 1/8 -7/1 138/20 0.75 0.125 -7.0 6.9
36.259
(30) + (6) + (0.2) + (0.05) + (0.009)
(3 * 101) + (6 * 100) + (2 * 10-1) + (5 * 10-2) + (9 * 10-3)
36.259 101 100 10-1 10-2 10-3 10 1 1/10 1/100 1/1000
062.732 81 80 8-1 8-2 8-3 8 1 1/8 1/64 1/512
10.111b 21 20 2-1 2-2 2-3 2 1 1/2 1/4 1/8
finite rational (rational with a fractional component which can be expressed with a finite number of digits) 3/4 -7/1 138/20 1/3 738/61 0.75 -7.0 6.9 0.33 12.0983606557…
a ratio with denominator 2a5b is finite in decimal a ratio with denominator 2a is finite in octal a ratio with denominator 2a is finite in hex a ratio with denominator 2a is finite in binary all ratios which are finite in binary are also finite in decimal some ratios which are finite in decimal are also finite in binary
rational as two integers 3/4 Numerator: 00000011 Denominator: 00000100 -7/13 Numerator: 11111001 Denominator: 00001101
(the computing equivalent of radix-point notation) fixed-point (the computing equivalent of radix-point notation) 57/8 111.001b Integer: 00000111 Fraction: 00100000
scientific notation engineering notation 362.354 = 3.62354 * 102 0.00736234 = 7.36234 * 10-3 989777.1 = 9.897771 * 105
(the computing equivalent of scientific notation) floating-point (the computing equivalent of scientific notation) 21/2 1010.1b 1.0101b * 23 Significand: 10101000 Exponent: 00000011
6.75
6.75 110b + 0.?b
0.75 3/4
3/4 1/2 + 1/4 2-1 + 2-2
6.75 = 110.11b
110.11b = 1.1011b * 22
1.1011b * 22 Significand: 11011000 Exponent: 00000010
(an international standard) IEEE floating-point (an international standard)
http://proglit.com/