Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems
Introduction (1) A number system is a well defined structured way of representing or expressing numbers as a combination of the elements of a finite set of mathematical symbols (i.e., digits). The functions of a number system are: – Represent a useful set of numbers. For example, all integers or rational numbers. – Give each number a standard representation. There are two major types of number systems. These are, 1. Positional number systems 2. Non positional number system
Introduction (2) 1. Positional number systems This uses the same symbol for different orders of magnitude This greatly simplifies arithmetic. Eg: Decimal, binary & hexadecimal number systems. 2. Non positional number system It combines digits to signify their sums or their differences. The sum/difference represents a number. Eg: Roman number system where MMXI represents 2011, IX represents 9. In this section we will consider Decimal, binary & hexadecimal number systems.
General Representation of a Number System In general, the number a 3 a 2 a 1 a 0 in a base b number system represents the following number: a 3 a 2 a 1 a 0 = a 3 * b 3 + a 2 * b 2 + a 1 * b 1 + a 0 * b 0 Base is the number of unique digits including zero. Eg: Decimal number system has 10 digits (0, 1 … 9). Therefore, the base is 10. Binary number system has 2 digits (0, 1). Therefore, the base is 2. Hexadecimal number system has 16 digits (0, F). Therefore, the base is 16.
Digits used for number systems
Counting under these number systems
Binary number system The binary number system represents numerical values using two symbols, 0 and 1. This is a positional number system. The binary system has a base of 2 with a radix of 2. In general a number could be represented as a binary number as follows, a n …a 3 a 2 a 1 a 0 = a n * 2 n +a 3 * a 2 * a 1 * a 0 * 2 0 These numbers are straightforward to implement, hence used in digital circuitry, logic gates and in almost all modern computers. 1 and 0 in binary numbers correspond to the ON and OFF in digital systems.
Most Significant Bit & Least Significant Bit Most Significant Bit (MSB) Least Significant Bit (LSB) Indicates the sign bit in some cases Indicates whether the number is odd or even
Decimal range covered by some commonly used bit values Bit valuesDecimal Range , ,294,967, × 10 19
Binary to Decimal Conversion Convert (1101) 2 to a decimal number. Convert 8 bit ( ) 2 to a decimal number. What is the MSB and LSB of the number?
Decimal to Binary Conversion – Power Method Step 1: Find the highest whole power of 2 contained in the decimal number. Step 2: Subtract the highest whole power of 2 from the decimal number. Step 3: Repeat Step 1 with the remainder. Step 4: Construct the binary number by placing a 1 in the position which corresponds to power value of the highest whole power of 2.
Decimal to Binary Conversion – Remainder Method Step 1: Divide the decimal number by the base (in the case of binary, divide by 2). Step 2: Indicate the remainder to the right. Step 3: Continue dividing into each quotient (and indicating the remainder) until the divide operation produces a zero quotient.
Hexadecimal Number System (1) Hexadecimal number system is a human-friendly binary number representation. Using this method it is possible to give the numbers a much compact representation. Each hexadecimal digit represents 4-bits. An 8-bit binary number can be represented by two hexadecimal digits. Eg: ( ) 2 can be represented by FE 16. ( ) 2 can be represented by Both the power method and remainder method applies to hexadecimal number system.
Hexadecimal Number System (2) Ex: Convert ABCDEF in hexadecimal into a decimal number. Convert into hexadecimal using the power method and the remainder method.
Decimal HexadecimalBinary
Representing Negative Numbers in Binary There are different techniques used to represent negative numbers in binary. These are, – Signed magnitude method – One's complement method – Two's complement method
Signed magnitude method This approach is directly similar to the most common way of constructing a sign. – i.e. placing ‘+’ or ‘-’ in front of a number According to this method the MSB indicates the sign of the number. – 0 indicates +ve & 1 indicates –ve Eg: 8-bit, = = Some of the early computers (eg. IBM 7090) used this method.
Signed magnitude method In signed magnitude, the left-most bit is not actually part of the number, but is just the equivalent of a + or - sign. Arithmetic operations Eg: 8-bit, = = = Answer = Is this correct? Can we use this for arithmetic operations? NO
One's complement method (1) Positive numbers are represented as a regular binary numbers. Negative numbers are represented differently. Under this method in order to negate a number, it replaces all zeros with ones, and ones with zeros i.e. take the compliment. Eg: +12 would be & -12 would be As in sign magnitude MSB indicates the sign (‘0’ is +ve, ‘1’ is -ve).
One's complement method (2) Representation of 4-bit binary in one’s compliment method. One drawback of this method is that it has two different representations of zero.
Two's complement method (1) Begin with the number in one's complement. Add 1 if the number is negative. Eg: – would be represented as , and as – To verify this, let's subtract 1 from , to get – If we flip the bits, we get , or 12 in decimal.
Converting Decimal to n-bit Binary using Two's complement method For Positive Numbers: 1.Convert the magnitude of the number to binary. 2.Add zeros to make the binary number an n-bit number. Ex: If your number consists of 5 bits but the goal is to get a number consisting 8-bits, pad the 5-bit binary number by adding three zeros to the left. For Negative Numbers: 1.Convert the magnitude of the number to binary. 2.Add zeros to the left to make the binary number to have n digits. 3.Complement the number (i.e., invert the bits). 4.Add 1 to the inverted binary number to get the n-bit 2's complement notation.
Converting n-bit 2's Complement Binary to Decimal 1. Look at the leftmost bit to determine whether the number is positive or negative. If the leftmost bit is 0, the number is positive. If the leftmost bit is 1, the number is negative. 2. If positive, convert the number from binary to decimal. 3. If negative, determine the magnitude by: – Invert the bits of the binary number. – Add 1 to the inverted number. – Convert the result of the addition operation to decimal to get the magnitude of the corresponding decimal number. – The actual decimal number is the negative of this number.
4-bit Binary in 2's Complement Method