Numbering System Base Conversion
Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
Why different number systems? Binary number result in quite a long string of 0s and 1s Easier for the computer to interpret input from the user
Base Conversion In daily life, we use decimal (base 10) number system Computer can only read in 0 and 1 Number system being used inside a computer is binary (base 2) Octal (base 8) and hexadecimal (base 16) are used in programming for convenience
Base Conversion Conversion Binary number, Octal number, Hexadecimal number, and Decimal number.
Base Conversion BinaryOctalHexadecimalDecimal A B C D E F15
Base Conversion For example: 62 = = 76 = 3E decimal binary octal hexadecimal 1For Decimal: 62 = 6x x For Binary: = 1x x x x x x2 0 3For Octal: 76 = 7x x8 0 4For Hexadecimal: 3E = 3x x16 0 Since for hexadecimal system, each digit contains number from 1 to 15, thus we use A, B, C, D, E and F to represent 10, 11, 12, 13, 14 and 15.
Binary and decimal system Binary to decimal X X X X X X X X. 2 0 Decimal to binary Keep dividing the number by two and keep track of the remainders. Arrange the remainders (0 or 1) from the least significant (right) to most significant (left) digits
Octal and Hexadecimal system Binary to Octal (8 = 2 3 ) Every 3 binary digit equivalent to one octal digit Binary to Hexadecimal (16 = 2 4 ) Every 4 binary digit equivalent to one hexadecimal digit Octal to binary Every one octal digit equivalent to 3 binary digit Hexadecimal to binary Every one hexadecimal digit equivalent to 4 binary digits
Base Conversion How to convert the decimal number to other number system e.g. convert in binary form 2 | | | | =
Base Conversion e.g. convert in octal form Since for octal form, one digit is equal to 3 digits in binary number, we can change binary number to octal number easily. e.g = Thus, = 22 8
Base Conversion e.g. convert in hexadecimal form Similarly, for hexadecimal form, one digit is equal to 4 digits in binary number. e.g = Thus, = 12 16
Numbering System Addition & Subtraction
Decimal Addition What is going on? (carry) (subtract the base)
Binary Addition Rules = = = = 2 = 10 2 = 0 with 1 to carry = 3 = 11 2 = 1 with 1 to carry
Binary Addition Verification = = 83 10
Binary Addition ex Verification ___ ___________ =
Octal Addition (subtract Base (8))
Octal Addition ex (subtract Base (8))
Hexadecimal Addition C F (subtract Base (16)) B 4 2 B 16
Hexadecimal Addition 8 A D D (subtract Base (16)) 16
Decimal Subtraction How it was done? ( add the base 10 when borrowing)
Binary Subtraction Verification = = 55 10
Binary Subtraction ex Verification ___ ___________ =
Octal Subtraction
Octal Subtraction ex
Hexadecimal Subtraction B 16 7 C F
Hexadecimal Subtraction 8 A D D
Let’s do some exercises! Octal, Hexadecimal, Binary Addition & Subtraction