Unit 3- Hexadecimal and Floating Point Numbers

13
Digital Electronic Systems Unit 3 Hexadecimal and Floating Point Numbers This section introduces hexadecimal numbers and outlines their relationship with other number systems such as decimal and binary. It also introduces floating-point numbers that are especially useful for representing very large and very small numbers in computing. Hexadecimal Numbers The Hexadecimal system is a number system based on sixteen symbols and is a compact way of expressing binary numbers. It is frequently used in microprocessor and computer applications. The system is based on the ten decimal digits and on the first six alphabetic characters. The subscript 16 is used to indicate that a number is Hexadecimal, for example, 10 16 . COUNT DECIMAL BINARY HEXADECIMAL. zero 0 0 2 0 16 one 1 1 2 1 16 two 2 10 2 2 16 three 3 11 2 3 16 four 4 100 2 4 16 five 5 101 2 5 16 six 6 110 2 6 16 seven 7 111 2 7 16 eight 8 1000 2 8 16 nine 9 1001 2 9 16 ten 10 1010 2 A 16 eleven 11 1011 2 B 16 twelve 12 1100 2 C 16 thirteen 13 1101 2 D 16 fourteen 14 1110 2 E 16 fifteen 15 1111 2 F 16 As can be seen a four digit binary number represents each Hexadecimal number. Counting in Hexadecimal is very similar also: 1

description

micr MCU Unitbeginners courseocontrollers and electronics course

Transcript of Unit 3- Hexadecimal and Floating Point Numbers

Page 1: Unit 3- Hexadecimal and Floating Point Numbers

Digital Electronic Systems Unit 3

Hexadecimal and Floating Point Numbers

This section introduces hexadecimal numbers and outlines their relationship with other number systems such as decimal and binary. It also introduces floating-point numbers that are especially useful for representing very large and very small numbers in computing.

Hexadecimal Numbers

The Hexadecimal system is a number system based on sixteen symbols and is a compact way of expressing binary numbers. It is frequently used in microprocessor and computer applications. The system is based on the ten decimal digits and on the first six alphabetic characters. The subscript 16 is used to indicate that a number is Hexadecimal, for example, 1016.

COUNT DECIMAL BINARY HEXADECIMAL.zero 0 02 016

one 1 12 116

two 2 102 216

three 3 112 316

four 4 1002 416

five 5 1012 516

six 6 1102 616

seven 7 1112 716

eight 8 10002 816

nine 9 10012 916

ten 10 10102 A16

eleven 11 10112 B16

twelve 12 11002 C16

thirteen 13 11012 D16

fourteen 14 11102 E16

fifteen 15 11112 F16

As can be seen a four digit binary number represents each Hexadecimal number. Counting in Hexadecimal is very similar also:

0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10,11,12,13,14,15,16,17,18,19,1A,1B,1C,1D,1E,1F,20,21.....

Binary to Hexadecimal conversion

Starting with the least significant bit take the binary number and group the digits into fours and then convert them directly using the table above. If the most significant grouping is too small, just add zeros to the left-hand side.

Ex 1: Convert the binary number 111001100011102 to a Hexadecimal number. [398E16]

Ex 2: Express the 32-bit memory location 11011111100111000001010100001110 in Hexadecimal. [DF9C150E16]

1

Page 2: Unit 3- Hexadecimal and Floating Point Numbers

Digital Electronic Systems Unit 3

Hexadecimal to Binary conversion

This is the reverse of the process for binary to hex, i.e. replace each Hexadecimal symbol with the appropriate four binary digits (bits).

Ex 3: Convert the Hexadecimal number D2E816 to a binary number. [11010010111010002]

Hexadecimal to Decimal conversion

Multiply the decimal value of each hexadecimal digit by it’s weighting. The weighting are increasing powers of 16, from right to left.

163=4096, 162=256, 161=16, 160=1.

Ex 4: Convert the Hexadecimal number B2F816 to a Decimal number. [4581610]

Decimal to Hexadecimal conversion

This conversion process uses successive division by sixteen. The hexadecimal number is generated from the remainders produced. The first remainder produced is the least significant digit.

Ex 5: Convert the Decimal number 650 into a Hexadecimal number. [28A16]

Floating-Point NumbersThe Floating-point number system, based on scientific notation, is capable of representing very large and very small numbers without increasing the number of bits required. A floating-point number consists of a three parts – a sign bit, an exponent and a mantissa. The mantissa represents the magnitude of the number and the exponent determines the position of the decimal point.

Consider the decimal number 241,506,800

To represent this integer in floating-point, it must be normalised by moving the decimal point to the left of all the digits leaving a fractional number (mantissa) and the exponent as follows:

Floating-point binary numbers

There are three different formats defined by ANSI/IEEE Standard 754-1985. These all have the same basic format, except for the number of bits they use.

single precision (32 bits) double precision (64 bits) extended precision (80 bits)

We will restrict our discussion to the single-precision floating-point format.

2

Page 3: Unit 3- Hexadecimal and Floating Point Numbers

Digital Electronic Systems Unit 3

Single-precision floating-point binary numbers

The range of floating point binary numbers that can be represented using single precision

To evaluate a binary number, given the number in single precision floating point format

The Number in binary is given by:

where S is the sign bit (either 1 or 0)F is the fractional part (mantissa) in binaryE is the biased exponent converted to decimal (The actual exponent is E-127)

Example

S E F1 10010001 10001110001000000000000

The biased exponent, E is converted to decimal.

1 0 0 1 0 0 0 12

1 * 20 = 1 * 1 = 110

0 * 21 = 0 * 2 = 010

0 * 22 = 0 * 4 = 010

0 * 23 = 0 * 8 = 010

1 * 24 = 1 * 16 = 1610

0 * 25 = 0 * 32 = 010

0 * 26 = 0 * 64 = 010

1 * 27 = 1 * 128 = 12810

Sum = 14510

Substitute into the single precision floating point formula:

The number (in binary) is

3

Page 4: Unit 3- Hexadecimal and Floating Point Numbers

Digital Electronic Systems Unit 3

Multiplying a binary number by is the same as shifting the binary point 18 places to the right. (This is analogous to shifting the decimal point n positions to the right when a decimal number is multiplied by .) Therefore the number is

This number can be converted to decimal, by determining the weights in all of the bit positions where the binary digit is 1, and adding them together. The number in decimal is

4

Page 5: Unit 3- Hexadecimal and Floating Point Numbers

Digital Electronic Systems Unit 3

SUMMARYNumber Systems:

Decimal (10 digits): 0,1,2,3,4,5,6,7,8,9 Binary (2 digits): 0,1 Hexadecimal (16 digits): 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F Octal (8 digits): 0,1,2,3,4,5,6,7

Decimal to Binary conversion

Successive division by 2 → remainder

Binary to Decimal conversion

Multiply each bit by it weight 2n and add

Binary Addition 02+02=02, 02+12=12, 12+02=12, 12+12=102, 12+12+12=112

Binary Subtraction 2’s complement the number that you are subtracting and add

Binary Multiplication 02*02=02, 02*12=02, 12*02=02, 12*12=12 - same method is used as in decimal long multiplication

Binary Division Same method is used as in decimal long division

1’s complement Change all 12’s to 02’s and all 02’s to 12’s

2’s complement 2’s complement = 1’s complement + 12

Octal to Decimal conversion

Multiply each octal digit by it weight 8n and add

Decimal to Octal conversion

Successive division by 8 → remainder

Binary to Octal conversion Group bits into threes and convert to Octal symbol

Octal to binary conversion Replace each Octal symbol with equivalent 3 bits

Binary to Hexadecimal Group bits into fours and convert to Hex symbol

Hexadecimal to Binary Replace each Hex symbol with equivalent 4 bits

Hexadecimal to Decimal Multiply each Hex digit by it weight 16n and add

Decimal to Hexadecimal Successive division by 16 → remainder

5

Page 6: Unit 3- Hexadecimal and Floating Point Numbers

Digital Electronic Systems Unit 3

Number Systems Revision Exercises

Decimal Numbers

Ex. 6What is the weight of the digit 6 in each of the decimal numbers?(a) 1,386(b) 54,692(c) 671,920

Ex. 7Express each of the following decimal numbers as a power of ten.(a) 10(b) 100(c) 10,000(d) 1,000,000

Binary Numbers

Ex. 8Convert the following binary numbers to decimal.(a) 112 [310](b) 1002 [410](c) 10112 [1110](d) 111112 [3110]

Ex. 9Convert the following binary numbers to decimal.(a) 110011.112 [51.7510](b) 1110001.00012 [113.062510](c) 1011010.10102 [90.62510]

Ex. 10What is the highest decimal number that can be represented by seven bits?

Ex. 11How many bits are required to represent the following decimal numbers?(a) 17 [5](b) 49 [6](c) 132 [8](d) 205 [8]

6

Page 7: Unit 3- Hexadecimal and Floating Point Numbers

Digital Electronic Systems Unit 3

Ex. 12Generate the binary sequence for the decimal sequence from 64 to 75.

Ex. 13Convert the following decimal numbers to binary.(a) 17 [100012](b) 59 [1110112](c) 73 [10010012](d) 186 [101110102]

Ex. 14Convert each of the following decimal numbers to binary (to 6 binary places).(a) 0.98 [0.1111102](b) 0.347 [0.0101102](c) 186.9028 [10111010.1110012]

Ex. 15Determine the 1’s complement of each binary number (assume 8-bit 1’s complement).(a) 110101112

(b) 11101012

Ex. 16Determine the 2’s complement of each binary number (assume 8-bit 2’s complement).(a) 110101112

(b) 11101012

Ex. 17Express each decimal number in binary as an 8-bit number in 2’s complement form.(a) –68 [101111002](b) +101 [011001012](c) –125 [100000112]

Ex. 18Determine the decimal value of each signed binary number (assume 8-bit 2’s complement).(a) 100110012 [-10310](b) 011101002 [11610](c) 101111112 [-6510]

Binary Arithmetic

Ex. 19Add the following binary numbers.(a) 10012 + 1012 [11102](b) 11012 + 10112 [110002]

7

Page 8: Unit 3- Hexadecimal and Floating Point Numbers

Digital Electronic Systems Unit 3

Ex. 20Convert each pair of decimal numbers to 8-bit binary in 2’s complement form and add.(a) 33 and 15 [001100002](b) 56 and –27 [000111012](c) –46 and 25 [-000101012](d) –110 and –84 [OVERFLOW]

Ex. 21Perform each addition (Each number is in 8-bit 2’s complement form.)(a) 100011002 + 001110012 [001110112](b) 110110012 + 111001112 [010000002]

Ex. 22Perform each subtraction using 8-bit 2’s complement. (a) 001100112 – 000100002 [001000112](b) 011001012 – 111010002 [011111012]

Ex. 23Multiply 011010102 by 111100012 (Each number is in 8-bit 2’s complement form.)

[1001110010102 in 12-bit 2’s complement form]Ex. 24

Divide 01000100 by 00011001 (Each number is in 8-bit 2’s complement form.)[10.101110000101000111102 recurring]

Hexadecimal Numbers

Ex. 25Convert each Hexadecimal number to binary(a) 5916 [010110012](b) FB1716 [11111011000101112]

Ex. 26Convert each binary number to Hexadecimal(a) 101112 [1716](b) 1001100000102 [98216]

Ex. 27Convert each hexadecimal number to decimal(a) EB16 [23510](b) 5C216 [147410]

Ex. 28Convert each decimal number to hexadecimal.(a) 52 [3416](b) 284 [11C16]

8