Data Representation

Number Systems

Summary

Place Value

  • The value of any digit depends on its position in the number.

  • The most significant digit (MSD) is the digit with the highest place value
  • The least significant digit (LSD) is the digit with the lowest place value

Binary System

  • Computers only ‘understand’ 0’s and 1’s. All the data inside a computer has to be represented by patterns of 1’s and 0’s
  • A bit is a binary digit, which can be a 1 or 0
  • A byte is taken to represent 8 bits

Conversion of Decimal to Base-n

  1. If N is zero, other number is also zero
  2. While N > 0,
  3. Find rem = N mod base
  4. Add this rem to the back of the base number (if rem > 9, other symbols used)
  5. N = N // base

Conversion of Base-n to Decimal

Let i be the index of the current place
  1. While i < Length(number),
  2. Find the current place value = base^i * value
  3. Add this to the decimal number

Conversion of a number from Binary to Hexadecimal

Binary to Hexadecimal

  • Starting from LSD, sector in groups of four
Insert dummy 0’s when there is not enough
  • For each group of four, calculate its decimal value, and it is the digit for hexadecimal

Hexadecimal to Binary

  • Starting from LSD, make four-bit groups of zero
  • For each digit, convert it into the binary representation