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 1084161084_{16} to binary.
      • Break 44 into its four-bit sequence: 01000100.
      • 88 becomes 10001000.
      • 00 becomes 00000000.
      • 11 becomes 00010001.
      • The binary equivalent is 00010000100001000001 0000 1000 0100.
  • 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 (16016^0).
    • The second character is the sixteens place (16116^1).
    • The third character is the 256s place (16216^2).
    • The fourth character is the 4,096s place (16316^3).

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 142142 in base 10 can be broken down as:
    • (1102)+(4101)+(2100)=100+40+2=142(1 * 10^2) + (4 * 10^1) + (2 * 10^0) = 100 + 40 + 2 = 142.
  • Hexadecimal: The sequence for hex numbers is based on powers of 16.
    • Ones place (16016^0).
    • Sixteens place (16116^1).
    • 256s place (16216^2).
    • 4,096s place (16316^3).

Examples

  • Example 1: Convert 1C161C_{16} to decimal.
    • (1161)+(12160)=16+12=2810(1 * 16^1) + (12 * 16^0) = 16 + 12 = 28_{10}.
  • Example 2: Convert 851685_{16} to decimal.
    • (8161)+(5160)=(816)+5=128+5=13310(8 * 16^1) + (5 * 16^0) = (8 * 16) + 5 = 128 + 5 = 133_{10}.
  • 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

  • Repeated division by 16.

Hexadecimal Addition

  • Think in decimal but subtract 16 for each carry-over.
  • Example: 23<em>16+16</em>16=391623<em>{16} + 16</em>{16} = 39_{16}. (Not 39 in decimal terms).
    • If the result exceeds 15, subtract 16 to carry over.
  • Example: 58<em>16+22</em>16=7A1658<em>{16} + 22</em>{16} = 7A_{16}.
  • Example: 2B<em>16+84</em>16=AF162B<em>{16} + 84</em>{16} = AF_{16}.

Complex Hexadecimal Addition

  • Example: DF<em>16+AC</em>16DF<em>{16} + AC</em>{16}.
    • FF (15) + CC (12) = 27. Since 27 > 15, subtract 16 resulting in 11 (BB) with a carry-over of 1.
    • DD (13) + AA (10) + 1 (carry-over) = 24. Since 24 > 15, subtract 16 resulting in 8 with a carry-over of 1.
    • Final Answer: 18B1618B_{16}.
  • 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>162A<em>{16}. Convert 2A</em>162A</em>{16} to binary, perform the two's complement operation, and the two’s complement is D616D6_{16}.
  • 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.
    • 808^0: Ones place.
    • 818^1: Eights place.
    • 828^2: 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 237482374_8 to decimal.
      • (283)+(382)+(781)+(480)(2 * 8^3) + (3 * 8^2) + (7 * 8^1) + (4 * 8^0)
      • (2512)+(364)+(78)+4(2 * 512) + (3 * 64) + (7 * 8) + 4
      • 1024+192+56+4=1276101024 + 192 + 56 + 4 = 1276_{10}.
  • 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>813<em>8 to binary. 3 is 011, 1 is 001, thus 13</em>813</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.