Chapter 2 Bits Data Types and Operations Hexadecimal
Chapter 2 Bits, Data Types, and Operations
Hexadecimal Notation It is often convenient to write binary (base-2) numbers as hexadecimal (base-16) numbers instead. • fewer digits -- four bits per hex digit • less error prone -- easy to corrupt long string of 1’s and 0’s Binary Hex Decimal 0000 0001 0010 0011 0100 0101 0110 0111 0 1 2 3 4 5 6 7 1000 1001 1010 1011 1100 1101 1110 1111 8 9 A B C D E F 8 9 10 11 12 13 14 15 2 -2
Convert Hexadecimal (2’s C binary) to Decimal Given a hex digit that represents 2’s complement binary, convert into a decimal. Example: 6 Fhex or x 6 F 1. Determine the sign of the number. If the msh (most significant hex) value is 8 or greater then the sign is negative. 6 Fhex, sign + b/c msh (6) < 8 sign positive 2. Use positional notation to convert 6 x 161 + Fx 160 = 6 x 161 + 15 = 96 + 15 = 111 6 Fhex = 111 ten 2 -3
Convert Hexadecimal (2’s C binary) to Decimal Given a hex digit that represents 2’s complement binary, convert into a decimal. Example: A 0 Fhex or x. A 0 F 1. Determine the sign of the number. If the msh (most significant hex) value is 8 or greater then the sign is negative. A 0 Fhex, sign - b/c msh (A) < 8 sign negative 2. Since negative, must apply 2’s complement FFF - A 0 F 5 F 0 + 1 5 F 1 A 0 F = - 5 F 1 3. Convert to signed magnitude to decimal with positional notation -(5 x 162 + Fx 161 + 1 x 160) = -(5 x 256 + 15 x 16 + 1) = -1, 521 2 -4
- Slides: 4