650 likes | 755 Views
Week-3 Introduction to Number Systems. Number systems and their conversions Decimal, Binary, Octal, Hexadecimal Arithmetic operations Binary Addition Binary Subtraction Binary Multiplications Binary Division Signed and Magnitude numbers Complement numbers Binary Coded decimal numbers.
E N D
Week-3Introduction to Number Systems • Number systems and their conversions • Decimal, Binary, Octal, Hexadecimal • Arithmetic operations • Binary Addition • Binary Subtraction • Binary Multiplications • Binary Division • Signed and Magnitude numbers Complement numbers • Binary Coded decimal numbers
Conversion Among Bases • The possibilities: Decimal Octal Binary Hexadecimal pp. 40-46
Binary to Decimal Decimal Octal Binary Hexadecimal
Binary to Decimal • Technique • Multiply each bit by 2n, where n is the “weight” of the bit • The weight is the position of the bit, starting from 0 on the right • Add the results
Example Bit “0” 1010112 => 1 x 20 = 1 1 x 21 = 2 0 x 22 = 0 1 x 23 = 8 0 x 24 = 0 1 x 25 = 32 4310
Octal to Decimal Decimal Octal Binary Hexadecimal
Octal to Decimal • Technique • Multiply each bit by 8n, where n is the “weight” of the bit • The weight is the position of the bit, starting from 0 on the right • Add the results
Example 7248 => 4 x 80 = 4 2 x 81 = 16 7 x 82 = 448 46810
Hexadecimal to Decimal Decimal Octal Binary Hexadecimal
Hexadecimal to Decimal • Technique • Multiply each bit by 16n, where n is the “weight” of the bit • The weight is the position of the bit, starting from 0 on the right • Add the results
Example ABC16 => C x 160 = 12 x 1 = 12 B x 161 = 11 x 16 = 176 A x 162 = 10 x 256 = 2560 274810
Decimal to Binary Decimal Octal Binary Hexadecimal
Decimal to Binary • Technique • Divide by two, keep track of the remainder • First remainder is bit 0 (LSB, least-significant bit) • Second remainder is bit 1 • Etc.
2 125 62 1 2 31 0 2 15 1 2 3 1 2 7 1 2 0 1 2 1 1 Example 12510 = ?2 12510 = 11111012
Decimal to Octal Decimal Octal Binary Hexadecimal
Decimal to Octal • Technique • Divide by 8 • Keep track of the remainder
8 19 2 8 2 3 8 0 2 Example 123410 = ?8 8 1234 154 2 123410 = 23228
Decimal to Hexadecimal • Technique • Divide by 16 • Keep track of the remainder
16 1234 77 2 16 4 13 = D 16 0 4 Example 123410 = ?16 123410 = 4D216
Octal to Binary Decimal Octal Binary Hexadecimal
Octal to Binary • Technique • Convert each octal digit to a 3-bit equivalent binary representation
7 0 5 111 000 101 Example 7058 = ?2 7058 = 1110001012
Hexadecimal to Binary Decimal Octal Binary Hexadecimal
Hexadecimal to Binary • Technique • Convert each hexadecimal digit to a 4-bit equivalent binary representation
1 0 A F 0001 0000 1010 1111 Example 10AF16 = ?2 10AF16 = 00010000101011112
Octal to Hexadecimal Decimal Octal Binary Hexadecimal
Octal to Hexadecimal • Technique • Use binary as an intermediary
1 0 7 6 • 001 000 111 110 2 3 E Example 10768 = ?16 10768 = 23E16
Hexadecimal to Octal Decimal Octal Binary Hexadecimal
Hexadecimal to Octal • Technique • Use binary as an intermediary
1 F 0 C • 0001 1111 0000 1100 1 7 4 1 4 Example 1F0C16 = ?8 1F0C16 = 174148
Don’t use a calculator! Exercise – Convert ... Skip answer Answer
Exercise – Convert … Answer
Common Powers (1 of 2) • Base 10
Common Powers (2 of 2) • Base 2 • What is the value of “k”, “M”, and “G”? • In computing, particularly w.r.t. memory, the base-2 interpretation generally applies
Binary Addition (1 of 2) • Two 1-bit values “two” pp. 36-38
Binary Addition (2 of 2) • Two n-bit values • Add individual bits • Propagate carries • E.g., 1 1 10101 21+ 11001 + 25 101110 46
Binary Subtraction • Two numbers can be subtracted by subtracting each pair of digits together with borrowing, where needed. Binary Arithmetic Operations
Binary Arithmetic Operations (5/6) • MULTIPLICATION • To multiply two numbers, take each digit of the multiplier and multiply it with the multiplicand. This produces a number of partial products which are then added. Binary Arithmetic Operations
Binary Arithmetic Operations (6/6) • Digit multiplication table: • DIVISION – can you figure out how this is done? • Exercise: Think of the division technique (shift & subtract) used for decimal numbers and apply it to binary numbers. Binary Arithmetic Operations
Multiplication (2 of 3) • Binary, two 1-bit values
Multiplication (3 of 3) • Binary, two n-bit values • As with decimal values • E.g., 1110 x 1011 1110 1110 0000 111010011010
Negative Numbers: Sign-and-Magnitude (1/4) • Negative numbers are usually written by writing a minus sign in front. • Example: - (12)10 , - (1100)2 • In sign-and-magnitude representation, this sign is usually represented by a bit: 0 for + 1 for - Negative Numbers: Sign-and-Magnitude
magnitude sign Negative Numbers:Sign-and-Magnitude (2/4) • Example: an 8-bit number can have 1-bit sign and 7-bit magnitude. Negative Numbers:Sign-and-Magnitude
1s and 2s Complement • Two other ways of representing signed numbers for binary numbers are: • 1s-complement • 2s-complement • They are preferred over the simple sign-and-magnitude representation. 1s and 2s Complement
1s Complement (1/3) • Given a number x which can be expressed as an n-bit binary number, its negative value can be obtained in 1s-complement representation using: - x = 2n - x - 1 Example: With an 8-bit number 00001100, its negative value, expressed in 1s complement, is obtained as follows: -(00001100)2 = - (12)10 = (28 - 12 - 1)10 = (243)10 = (11110011)1s 1s Complement
1s Complement (2/3) • Essential technique: invert all the bits. Examples: 1s complement of (00000001)1s = (11111110)1s 1s complement of (01111111)1s = (10000000)1s • Largest Positive Number: 0 1111111 +(127)10 • Largest Negative Number: 1 0000000 -(127)10 • Zeroes: 0 0000000 1 1111111 • Range: -(127)10 to +(127)10 • The most significant bit still represents the sign: 0 = +ve; 1 = -ve. 1s Complement
1s Complement (3/3) • Examples (assuming 8-bit binary numbers): (14)10 = (00001110)2 = (00001110)1s -(14)10 = -(00001110)2 = (11110001)1s -(80)10 = -( ? )2 = ( ? )1s 1s Complement
2s Complement (1/4) • Given a number x which can be expressed as an n-bit binary number, its negative number can be obtained in 2s-complement representation using: - x = 2n - x Example: With an 8-bit number 00001100, its negative value in 2s complement is thus: -(00001100)2 = - (12)10 = (28 - 12)10 = (244)10 = (11110100)2s 2s Complement