700 likes | 1.87k Views
NUMBER SYSTEMS. The BASE of a number system. Determines the number of digits available In our number system we use 10 digits: 0-9 The base in our system is 10 It is called decimal or denary. The BASE of a number system. Computers are bi-stable devices
E N D
The BASE of a number system • Determines the number of digits available • In our number system we use 10 digits: 0-9 • The base in our system is 10 • It is called decimal or denary
The BASE of a number system • Computers are bi-stable devices • A bi-stable device has only two possible states: ON or OFF • Hence a base 2 number system is enough for such devices • A base 2 number system is called binary • The 2 possible digits are 0 and 1
The BASE of a number system • An other number system used with computers is Hexadecimal • The base for this system is 16 • The 16 possible digits are 0 – 9 and A - F
Place values • The position of each number within a series of numbers is very important • The position of the number determines how large it is • All number bases have their place values
Place values In base 10, the place values are as follows: Values go up in powers of 10 as you move from left to right
Place values In base 2, the place values are as follows: Values go up in powers of 10 as you move from left to right.
Binary to Decimal Conversion To convert binary numbers to decimal we need to follow these four steps: • Write down the place values, starting from the right hand side • Write each binary digit under its place value • Multiply each binary digit by its place value • Add up the total number
Binary to Decimal Conversion Example Convert the binary number 10101 to decimal. Answer: 101012 = 2110
Decimal to Binary Conversion To convert a decimal number to binary • Successively divide the decimal number by 2 and record the remainder • Use the numerator for the next division until the result of the division is 0 • The remainder (1 or 0) of each division makes up the binary number
Decimal to Binary Conversion To convert a decimal number to binary • The remainder of the first division gives the LEAST significant bit • The remainder of the next division gives the NEXT bit etc. • This method produces the bits in reverse order - reading down the way gives the bits in order of right to left
Decimal to Binary Conversion Example Convert 3710 in binary Answer : 3710 = 1001012
Decimal to Binary Conversion An alternative method is to use the place values. To convert a decimal number to binary follow these steps: • Write down the place values up to the one which is just greater than the decimal number we need to convert
Decimal to Binary Conversion Let us consider the decimal number 37, we would need to write down the place values up to 64
Decimal to Binary Conversion 2. Work through the place values deciding on whether to place a 1 or a 0 under the place value
Decimal to Binary Conversion Since 37 is less than 64 we write a 0 under the 64. We would need a 32 so we write a 1 under the 32
Decimal to Binary Conversion This would leave us with 37 – 32 = 5. Now we are left with 5 to distribute under the other place values. Since 5 is less than 16 and 8 we write a 0 under both. We can now place a 1 under 4. This leaves us with 5 – 4 = 1. Hence we put a 0 under 2 and a 1 under 1. So 3710 = 1001012
The Hexadecimal (Hex) number system • Base 16 • 16 symbols: 0 – 9 & A – F • Place values increase in powers of 16 The advantage of the hexadecimal system is its usefulness in converting directly from a 4-bit binary number
Hex to Decimal Conversion To convert Hex numbers to decimal we need to follow these four steps: • Write down the place values, starting from the right hand side • Write each hex digit under its place value • Multiply each hex digit by its place value • Add up the total number
Hex to Decimal Conversion Example Convert 3CD16 to its decimal equivalent. Answer: 3CD16 = 97310
Decimal to Hex Conversion To convert a decimal number to hex • Successively divide the decimal number by 16 and record the remainder • Use the numerator for the next division until the result of the division is 0 • The remainder of each division makes up the hex number
Decimal to Hex Conversion Example 1 Convert 4110 to hex Answer : 4110 = 2916
Decimal to Hex Conversion Example 3 Convert 10910 to hex Answer : 10910 = 6 1316 = 6D16
Decimal to Hex Conversion An alternative method is to use the place values. To convert a decimal number to hex follow these steps: • Write down the place values up to the one which is just greater than the decimal number we need to convert
Decimal to Hex Conversion Let us consider the decimal number 356, we would need to write down the place values up to 4096
Decimal to Hex Conversion 2. Work through the place values deciding on weather to place a 0 or a value from 1 - 15under the place value.
Decimal to Hex Conversion Since 356 is less than 4096 we write a 0 under the 4096. We would need a 256 so we write a 1 under the 256.
Decimal to Hex Conversion This would leave us with 356 – 256 = 100. Now we are left with 100 to distribute under the other place values. Since 100 ÷ 16 = 6 r 4 we write a 6 under 16. This leaves us with 4 ones. Hence we put a 4 under 1. So 35610 = 16416
Binary to Hex Conversion To convert numbers from binary to hex and vice versa, we need to use the conversion table shown below
Binary to Hex Conversion For each digit in the hex number, write down the equivalent 4-bit binary digit. Example Convert C316 to its binary equivalent Answer : C316 = 110000112
Hex to Binary Conversion Divide the binary number into 4-bit groups starting from the right (LSB). If we end up with a group of less than 4 bits on the left, add 0s to fill up the required places. Then translate each group into its equivalent hexadecimal number below.
Hex to Binary Conversion Example Convert 10111010102 to hexadecimal Answer : 10111010102 = 2EA16
Addition of Binary Numbers 0 1 1 0 1 + 1 0 0 0 1 1 1 1 1 0 13 + 17 30 • Note: • 3 + 7 = 10 which we write as 0 carry 1. Similarly in binary: 1 + 1 = 0 carry 1.
Addition of Binary Numbers 13 + 17 1 31 0 1 1 0 1 + 1 0 0 0 1 0 0 0 0 1 1 1 1 1 1 • Note: • 3 + 7 + 1= 11 which we write as 1 carry 1. Similarly in binary: 1 + 1 + 1 = 1 carry 1.
1 0 1 0 0 Numeric Overflow 13 + 17 11 41 0 1 1 0 1 + 1 0 0 0 1 0 1 0 1 1 0 1 0 0 1 1 • Note: • The number 41 cannot be represented using 5 bits since with 5 bits we can represent the range from 0 to 31. Numeric overflow occurs if a number too large to be represented is encountered. For example a 5 bit register is used to store the decimal number 41.
Negative Numbers Negative numbers can be represented in binary using one of the following ways: • Sign and Magnitude Codes (SM) • Two's Complement (2C)
Sign and Magnitude Codes • The Most Significant Bit is used to represent the sign of the number 1 ve 0 ve • The other bits represent the magnitude of the number.
Example: Sign and Magnitude • Convert 24 to Sign and Magnitude representation using an 8-bit register format. In binary 24 1 1 0 0 0 Using 7 bits 24 0 0 1 1 0 0 0 SM 24 0 0 0 1 1 0 0 0 O since number is positive
Example: Sign and Magnitude • Convert - 24 to Sign and Magnitude representation using an 8-bit register format. In binary 24 1 1 0 0 0 Using 7 bits 24 0 0 1 1 0 0 0 SM 24 1 0 0 1 1 0 0 0 1 since number is negative
Two's Complement (2C) • The bits have the same place values as binary numbers. • However the Most Significant Bit is also used to represent the sign of the number. 1 ve 0 ve
Example: Two's Complement • Complement 67 using a 9-bit register In binary 67 0 1 0 0 0 0 0 1 1 Reverse Bits 1 0 1 1 1 1 1 0 0 Add 1 1 0 1 1 1 1 1 0 1 This gives -67
Range for 2C Representation 0 0 0 represents 0 0 represents 0 1-bit register 0 0 1 represents 1 1 represents -1 0 1 0 represents 2 1-bit register -1 , 0 0 1 1 represents 3 3-bit register 1 0 0 represents -4 0 0 represents 0 1 0 1 represents -3 0 1 represents 1 2-bit register 1 1 0 represents -2 1 0 represents -2 1 1 1 represents -1 1 1 represents -1 3-bit register 2-bit register -4, -3, -2, -1, 0, 1, 2, 3 -2, -1, 0, 1
Range for 2C Representation • In general an N-bit register can represent binary numbers in the range - 2N-1 ... + 2N-1- 1.
Binary Subtraction Example: Subtract 54 from 103 Can be written as 103 + (- 54) 103 - 54 Step 1: Check how many bits you need 103 8 bits (range for +ve numbers is 0 …2n-1) -54 7 bits (range for 2C numbers is 2n-1 to + 2n-1-1) Therefore we are going to use 8 bits in both cases.
Binary Subtraction Step 2: Convert - 54 to a 2C binary number The 9th bit or overflow bit will be ignored thus the 8-bit answer is correct. -54 1 1 0 0 1 0 1 02 Step 3: Convert 103 to a binary number 103 0 1 1 0 0 1 1 12 Step 4: Add binary 103 to - 54 0 1 1 0 0 1 1 12 + 1 1 0 0 1 0 1 02 1 0 0 1 1 0 0 0 12 Overflow bit 0 0 1 1 0 0 0 12
Binary Multiplication Decimal System Binary System • Shifting the number left multiplies that number by 10 • Shifting the number left multiplies that number by 2 420 = 42 x 10. 111000 = 11100 x 2