Number System Conversions and Arithmetic
Hexadecimal Conversions
- Hex to Binary: Break the hexadecimal number into four-bit groups, starting from the right, and replace each group with its hexadecimal equivalent.
- Example: Convert 108416 to binary.
- Break 4 into its four-bit sequence: 0100.
- 8 becomes 1000.
- 0 becomes 0000.
- 1 becomes 0001.
- The binary equivalent is 0001000010000100.
- Negative Hexadecimal Numbers: Use two's complement; a method will be covered but is not on the test.
Hexadecimal to Decimal Conversion
- Method 1: Convert hexadecimal to binary (four-bit groups), then convert binary to decimal.
- Method 2: Use the sum of weights method.
- The first character is the ones place (160).
- The second character is the sixteens place (161).
- The third character is the 256s place (162).
- The fourth character is the 4,096s place (163).
Visual Aid for Number System Conversions
- A visual aid is available on Teams to help organize conversions between hexadecimal, binary, and decimal.
- Four bits per hex character when converting to binary.
- Three bits represent an octal character.
- Blue indicates the sum of weights method.
- Red indicates repeated division.
- BCD (Binary Coded Decimal) will be covered in a later lecture.
Applying Sum of Weights in Decimal and Hexadecimal
- Decimal Example: The number 142 in base 10 can be broken down as:
- (1∗102)+(4∗101)+(2∗100)=100+40+2=142.
- Hexadecimal: The sequence for hex numbers is based on powers of 16.
- Ones place (160).
- Sixteens place (161).
- 256s place (162).
- 4,096s place (163).
Examples
- Example 1: Convert 1C16 to decimal.
- (1∗161)+(12∗160)=16+12=2810.
- Example 2: Convert 8516 to decimal.
- (8∗161)+(5∗160)=(8∗16)+5=128+5=13310.
- An alternate method is to convert the hexadecimal to its four-bit binary sequences (nibbles) and then use the sum of weights method.
Converting Decimal to Hexadecimal
Hexadecimal Addition
- Think in decimal but subtract 16 for each carry-over.
- Example: 23<em>16+16</em>16=3916. (Not 39 in decimal terms).
- If the result exceeds 15, subtract 16 to carry over.
- Example: 58<em>16+22</em>16=7A16.
- Example: 2B<em>16+84</em>16=AF16.
Complex Hexadecimal Addition
- Example: DF<em>16+AC</em>16.
- F (15) + C (12) = 27. Since 27 > 15, subtract 16 resulting in 11 (B) with a carry-over of 1.
- D (13) + A (10) + 1 (carry-over) = 24. Since 24 > 15, subtract 16 resulting in 8 with a carry-over of 1.
- Final Answer: 18B16.
- The process involves carrying over values, similar to decimal addition, but subtracting by 16 instead of 10.
Hexadecimal Subtraction Using Two's Complement
- Convert the hexadecimal number to binary, perform the two's complement on the binary, and then convert back to hex.
Methods for Computing Two's Complement of Hexadecimal Numbers
- Method 1: Convert to binary, perform two's complement, convert back to hex.
- Example: Find the two's complement of 2A<em>16. Convert 2A</em>16 to binary, perform the two's complement operation, and the two’s complement is D616.
- Method 2: Subtract from the maximum value and add one.
- Method 3: A translation table where each hex digit is converted to its complement and then one is added.
Octal Number System
- Base 8, using digits 0 through 7.
- Octal values:
- 10 (in decimal) is represented as 12 in octal (1 eight and 2 ones).
- 11: 13
- Weighted values are powers of 8.
- 80: Ones place.
- 81: Eights place.
- 82: 64s place.
Octal to Decimal Conversion
- Use the sum of weights method.
- Multiply the character by the weighted column, then add the next weighted portion.
- Example: Convert 23748 to decimal.
- (2∗83)+(3∗82)+(7∗81)+(4∗80)
- (2∗512)+(3∗64)+(7∗8)+4
- 1024+192+56+4=127610.
- Repeated division by 8 to convert a decimal to octal.
Octal to Binary Conversion
- Each octal character is represented by three bits.
- To convert, replace each octal digit with its three-bit binary equivalent and concatenate.
- Example: Convert 13<em>8 to binary. 3 is 011, 1 is 001, thus 13</em>8 is 001011.
Binary to Octal Conversion
- Start at the least significant bit (LSB).
- Group the bits into groups of three.
- Convert each group to an octal character.
Key Takeaways
- Convert everything to binary as an intermediary step.