Number Systems




Their are many different number systems. Base 10 is what we use. But we have base 2 (binary), base 3, etc.

Examples:


Base 10 place value system (powers of 10):  
... 104  103 102 101 100:

_____  _____  _____  _____  _____
10000   1000    100     10      1  

The number 237 is:
_____  _____  ____2  ____3  ____7  or 2x100 + 3x10 + 7x1
10000   1000    100     10      1  


Note: There are 10 symbols that we use (0 1 2 3 4 5 6 7 8 9)


Base 2 (binary) place value system (powers of 2): ... 24 23 22 21 20: _____ _____ _____ _____ _____ 16 8 4 2 1 The number 101102 is 22 in our base 10 system: ____1 ____0 ____1 ____1 ____0 or 1x16 + 0x8 + 1x4 + 1x2 + 0x1 = 22 16 8 4 2 1 The number 101112 is 23 in our base 10 system: ____1 ____0 ____1 ____1 ____1 or 1x16 + 0x8 + 1x4 + 1x2 + 1x1 = 23 16 8 4 2 1 The number 111112 is 31 in our base 10 system: ____1 ____1 ____1 ____1 ____1 or 1x16 + 1x8 + 1x4 + 1x2 + 1x1 = 31 16 8 4 2 1 Note: There are 2 symbols that we use (0 1) The int memory location uses 32 bits (the left most bit is a sign bit). The left bits are not shown above. If the left most bit is a zero, the number is positive else negative. Negative numbers are stored in twos complement form. 00000000000000000000000000000110 represents the number 6 as an int. 11111111111111111111111111111111 represents the number -1 as an int. (to convert to a positive 1, flip all the bits and then add 1.) 00000000000000000000000000000001 represents the number 1 as an int. Integer.toBinaryString(int value base 10) returns a String in base binary
Base 3 place value system (powers of 3): ... 34 33 32 31 30: _____ _____ _____ _____ _____ 81 27 9 3 1 The number 001203 is 15 in our base 10 system: ____0 ____0 ____1 ____2 ____0 or 0x81 + 0x27 + 1x9 + 2x3 + 0x1 = 15 81 27 9 3 1 The number 002203 is 24 in our base 10 system: ____0 ____0 ____2 ____2 ____0 or 0x81 + 0x27 + 2x9 + 2x3 + 0x1 = 24 81 27 9 3 1 The number 002213 is 25 in our base 10 system: ____0 ____0 ____2 ____2 ____1 or 0x81 + 0x27 + 2x9 + 2x3 + 1x1 = 25 81 27 9 3 1 Note: There are 3 symbols that we use (0 1 2) Integer.parseInt(String num, int base) returns the converted num as an int Integer.parseInt("101",2) would return 5
Base 8 (Octal) place value system (powers of 8): ... 84 83 82 81 80: _____ _____ _____ _____ _____ 4096 512 64 8 1 The number 000258 is 21 in our base 10 system: ____0 ____0 ____0 ____2 ____5 or 0x4096 + 0x512 + 0x64 + 2x8 + 5x1 = 21 4096 512 64 8 1 The number 000378 is 31 in our base 10 system: ____0 ____0 ____0 ____3 ____7 or 0x4096 + 0x512 + 0x64 + 3x8 + 7x1 = 31 4096 512 64 8 1 The number 002378 is 159 in our base 10 system: ____0 ____0 ____2 ____3 ____7 or 0x4096 + 0x512 + 2x64 + 3x8 + 7x1 = 159 4096 512 64 8 1 Note: There are 8 symbols that we use (0 1 2 3 4 5 6 7) Integer.toOctalString(int value) returns a String in base 8 Integer.parseInt(String num, int base) returns the converted num as an int Integer.parseInt("52",2) would return 42
Base 16 (Hex or Hexadecimal) place value system (powers of 16): ... 164 163 162 161 160: _____ _____ _____ _____ _____ 65536 4096 256 16 1 The number 0002516 is 37 in our base 10 system: ____0 ____0 ____0 ____2 ____5 or 0x65536 + 0x4096 + 0x256 + 2x16 + 5x1 = 37 65536 4096 256 16 1 The number 0002B16 is 43 in our base 10 system: ____0 ____0 ____0 ____2 ____B or 0x65536 + 0x4096 + 0x256 + 2x16 + 11x1 = 43 65536 4096 256 16 1 The number 0002F16 is 47 in our base 10 system: ____0 ____0 ____0 ____2 ____F or 0x65536 + 0x4096 + 0x256 + 2x16 + 15x1 = 47 65536 4096 256 16 1 The number 000AC16 is 172 in our base 10 system: ____0 ____0 ____0 ____A ____C or 0x65536 + 0x4096 + 0x256 + 10x16 + 12x1 = 172 65536 4096 256 16 1 The number 0001016 is 16 in our base 10 system: ____0 ____0 ____0 ____1 ____0 or 0x65536 + 0x4096 + 0x256 + 1x16 + 0x1 = 16 65536 4096 256 16 1 Note: There are 16 symbols that we use (0 1 2 3 4 5 6 7 8 9 A B C D E F) A represents 10 objects, B represents 11 objects, etc. Integer.toHexString(int value base 10) returns a String in base 16 Integer.parseInt(String num, int base) returns the converted num as an int Integer.parseInt("1A",2) would return 26 There is a short cut to convert base 16 numbers into base 8 or base 2. In order to convert into binary, rewrite each hex digit as a 4 bit binary number. In order to convert into base 8, regroup the binary bits into groups of 3, and then write the base 8 digit for each group of 3 bits (right to left) For example, since A16 is 1010 in base 2 and C16 is 1100 in base 2, we can write AC16 = 101011002 A C 2 5 4 1010 1100 --> 10 101 100
Hexadecimal Binary Binary Base 8 Base 10
AC16 1010 11002 10 101 1002 2548 172
BF16 1011 11112 10 111 1112 2778 191
FF16 1111 11112 11 111 1112 3778 255
Hex Binary Place Value Base 10 0 0000 0x8 + 0x4 + 0x2 + 0x1 0 1 0001 0x8 + 0x4 + 0x2 + 1x1 1 2 0010 0x8 + 0x4 + 1x2 + 0x1 2 3 0011 0x8 + 0x4 + 1x2 + 1x1 3 4 0100 0x8 + 1x4 + 0x2 + 0x1 4 5 0101 0x8 + 1x4 + 0x2 + 1x1 5 6 0110 0x8 + 1x4 + 1x2 + 0x1 6 7 0111 0x8 + 1x4 + 1x2 + 1x1 7 8 1000 1x8 + 0x4 + 0x2 + 0x1 8 9 1001 1x8 + 0x4 + 0x2 + 1x1 9 A 1010 1x8 + 0x4 + 1x2 + 0x1 10 B 1011 1x8 + 0x4 + 1x2 + 1x1 11 C 1100 1x8 + 1x4 + 0x2 + 0x1 12 D 1101 1x8 + 1x4 + 0x2 + 1x1 13 E 1110 1x8 + 1x4 + 1x2 + 0x1 14 F 1111 1x8 + 1x4 + 1x2 + 1x1 15
Run Binary Math Converter Applet (Java JRE Required)