03-NumberSystems.pptx - ICS 212 Program Structure William McDaniel Albritton M.S Memory Allocation Numeric Systems Decimal Binary Hexadecimal Converting

# 03-NumberSystems.pptx - ICS 212 Program Structure William...

This preview shows page 1 - 17 out of 47 pages.

ICS 212 Program Structure William McDaniel Albritton M.S. Memory Allocation Numeric Systems Decimal, Binary, Hexadecimal Converting Integer Representation Character Representation  Numeric Systems Decimal (base 10) Uses positional representation Each digit corresponds to a power of 10 based on its position in the number The powers of 10 increment from 0, 1, 2, etc. as you move right to left 1,479 = 1 * 10 3 + 4 * 10 2 + 7 * 10 1 + 9 * 10 0 Binary (base 2) Two digits: 0, 1 To make the binary numbers more readable, the digits are often put in groups of 4 1010 = 1 * 2 3 + 0 * 2 2 + 1 * 2 1 + 0 * 2 0 = 8 + 2 = 10 decimal 1100 1001 = 1 * 2 7 + 1 * 2 6 + 1 * 2 3 + 1 * 2 0 = 128 + 64 + 8 + 1 = 201 decimal Shorter and easier to read than binary 16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F “0x” often precedes hexadecimal numbers 0x123 = 1 * 16 2 + 2 * 16 1 + 3 * 16 0 = 1 * 256 + 2 * 16 + 3 * 1 = 256 + 32 + 3 = 291 decimal Hexadecimal (base 16) Hexadecimal (base 16) Another example 0xABC = A * 16 2 + B * 16 1 + C * 16 0 = 10 * 256 + 11 * 16 + 12 * 1 = 2560 + 176 + 12 = 2748 decimal 0000 0 0 0001 1 1 0010 2 2 0011 3 3 0100 4 4 0101 5 5 0110 6 6 0111 7 7 Binar y Decim al Hexadeci mal 1000 8 8 1001 9 9 1010 10 A 1011 11 B 1100 12 C 1101 13 D 1110 14 E 1111 15 F 10000 16 10 Binar y Decim al Hexadeci mal Converting From binary or hex to decimal Use positional representation as shown previously From decimal to binary (or hex) Keep dividing by 2 (or 16) Remainders give the digits, starting from lowest power Converting From binary to hex (or vice versa) Replace each set of four binary digits by the corresponding hexadecimal digit (or vice versa) Convert Decimal to Binary 22 decimal = 10110 binary Calculations: 2 |22 r. 0 2 |11 r. 1 2 | 5 r. 1 2 | 2 r. 0 2 | 1 r. 1 0 Convert Decimal to Binary 22 decimal = 10110 binary Calculations: Write down powers of 2 Subtract the largest power of 2 that is less than the number Add a 1 if can subtract, and a 0 if cannot 22 6 2 32 16 8 4 2 1 0 1 0 1 1 0 Other Bases Base 8 (octal number system) 123 = 1 * 8 2 + 2 * 8 1 + 3 * 8 0 = 1 * 64 + 2 * 8 + 3 * 1 = 64 + 16 + 3 = 83 decimal Other Bases  #### You've reached the end of your free preview.

Want to read all 47 pages?

• Spring '18
• Binary numeral system,  Shorter,  Keep,  Remainders
• • •  