Data Representation
Number Systems

Number Systems

A number system with base, or radix, rr is a system that uses distinct symbols for rr digits. Numbers in this system are represented by a string of these digit symbols. To determine the quantity that a number represents, each digit is multiplied by an integer power of rr and then summed up.

Decimal Number System (Base 10)

The decimal number system, which we use in everyday life, employs the radix 10 system. The 10 symbols used are:

0,1,2,3,4,5,6,7,8,90, 1, 2, 3, 4, 5, 6, 7, 8, 9

For example, the number 724.5 in decimal notation is interpreted as:

724.510=7×102+2×101+4×100+5×101724.5_{10} = 7 \times 10^2 + 2 \times 10^1 + 4 \times 10^0 + 5 \times 10^{-1}

This means:

  • 7×1027 \times 10^2 represents 7 hundreds
  • 2×1012 \times 10^1 represents 2 tens
  • 4×1004 \times 10^0 represents 4 units
  • 5×1015 \times 10^{-1} represents 5 tenths

Binary Number System (Base 2)

The binary number system uses radix 2. It employs the two symbols:

0,10, 1

For example, the binary number 101101 is interpreted as:

1011012=1×25+0×24+1×23+1×22+0×21+1×20=4510101101*2 = 1 \times 2^5 + 0 \times 2^4 + 1 \times 2^3 + 1 \times 2^2 + 0 \times 2^1 + 1 \times 2^0 = 45*{10}

To distinguish between numbers of different bases, we enclose the digits in parentheses and place the radix as a subscript. For example, to denote the equivalence between decimal and binary representations of forty-five, we write:

(101101)2=(45)10(101101)_2 = (45)_{10}

Octal and Hexadecimal Number Systems

Besides the decimal and binary systems, the octal (radix 8) and hexadecimal (radix 16) systems are significant in digital computing.

Octal Number System (Base 8)

The octal system uses eight symbols:

0,1,2,3,4,5,6,70, 1, 2, 3, 4, 5, 6, 7

For example, the octal number 736.4 is converted to decimal as follows:

(736.4)8=7×82+3×81+6×80+4×81=7×64+3×8+6×1+4×0.125=478.510(736.4)_8 = 7 \times 8^2 + 3 \times 8^1 + 6 \times 8^0 + 4 \times 8^{-1} = 7 \times 64 + 3 \times 8 + 6 \times 1 + 4 \times 0.125 = 478.5_{10}

Hexadecimal Number System (Base 16)

The hexadecimal system uses sixteen symbols:

0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

Here, the symbols A, B, C, D, E, and F correspond to decimal numbers 10, 11, 12, 13, 14, and 15 respectively. For example, the hexadecimal number F3 is converted to decimal as follows:

(F3)16=F×161+3×160=15×16+3=24310(F3)_{16} = F \times 16^1 + 3 \times 16^0 = 15 \times 16 + 3 = 243_{10}

Conversion from Decimal to Other Bases

To convert a number from decimal to another base rr:

  1. Separate the number into its integer and fractional parts.
  2. Convert the integer part by successive divisions by rr, collecting the remainders.
  3. Convert the fractional part by successive multiplications by rr, collecting the integer parts of the results.

Example: Decimal to Binary Conversion

Convert the decimal number 41.6875 to binary.

Integer Part

  1. Divide 41 by 2:

QuotientRemainder41÷2=20120÷2=10010÷2=505÷2=212÷2=101÷2=01\begin{array}{c|c} \text{Quotient} & \text{Remainder} \\ \hline 41 \div 2 = 20 & 1 \\ 20 \div 2 = 10 & 0 \\ 10 \div 2 = 5 & 0 \\ 5 \div 2 = 2 & 1 \\ 2 \div 2 = 1 & 0 \\ 1 \div 2 = 0 & 1 \\ \end{array}

The binary representation of 41 is obtained from the remainders read bottom-up:

(41)10=1010012 (41)_{10} = 101001 * 2

Fractional Part

  1. Multiply 0.6875 by 2:

FractionInteger Part0.6875×2=1.37510.375×2=0.7500.75×2=1.510.5×2=1.01\begin{array}{c|c} \text{Fraction} & \text{Integer Part} \\ \hline 0.6875 \times 2 = 1.375 & 1 \\ 0.375 \times 2 = 0.75 & 0 \\ 0.75 \times 2 = 1.5 & 1 \\ 0.5 \times 2 = 1.0 & 1 \\ \end{array}

The binary representation of 0.6875 is obtained from the integer parts:

0.687510=0.101120.6875_{10} = 0.1011_2

Combining both parts, the binary representation of 41.6875 is:

41.687510=101001.1011241.6875_{10} = 101001.1011_2

Conversion Between Binary, Octal, and Hexadecimal

Conversion between binary, octal, and hexadecimal systems is straightforward due to their bases being powers of 2.

Binary to Octal Conversion

Each octal digit corresponds to three binary digits since 23=82^3 = 8.

Binary to Hexadecimal Conversion

Each hexadecimal digit corresponds to four binary digits since 24=162^4 = 16.

Example: Binary to Octal and Hexadecimal Conversion

Consider a 16-bit binary number:

101010011000111021010100110001110_2

Binary to Octal

Partition into groups of three bits starting from the right:

1010100110001110\begin{array}{c|c|c|c|c|c} 1 & 010 & 100 & 110 & 001 & 110 \\ \end{array}

This gives the octal representation:

1246168124616_8

Binary to Hexadecimal

Partition into groups of four bits starting from the right:

1010100110001110\begin{array}{c|c|c|c} 1010 & 1001 & 1000 & 1110 \\ \end{array}

This gives the hexadecimal representation:

A98E16A98E_{16}

Binary-Coded Decimal (BCD)

A binary code that represents each decimal digit using a fixed number of binary digits (typically four) is called Binary-Coded Decimal (BCD).

Example: BCD Representation

For example, the decimal number 99 in BCD is:

910=100129910=1001 1001BCD9*{10} = 1001_2 \\ 99*{10} = 1001\ 1001_{BCD}

Alphanumeric Representation

In many computer applications, data includes not only numbers but also letters and special characters.

ASCII Code

The standard alphanumeric binary code is ASCII (American Standard Code for Information Interchange), which uses seven bits to code 128 characters. For example, the binary codes for the uppercase letters A to Z and the digits 0 to 9 are:

CharacterBinary CodeCharacterBinary Code
A100 00010011 0000
B100 00101011 0001
C100 00112011 0010
D100 01003011 0011
E100 01014011 0100
F100 01105011 0101
G100 01116011 0110
H100 10007011 0111
I100 10018011 1000
J100 10109011 1001
K100 1011space010 0000
L100 1100.010 1110
M100 1101(010 1000
N100 1110+010 1011
O100 1111$010 0100
P101 0000*010 1010
Q101 0001)010 1001
R101 0010-010 1101
S101 0011/010 1111
T101 0100,010 1100
U101 0101=011 1101
V101 0110
W101 0111
X101 1000
Y101 1001
Z101 1010

Binary codes are crucial for representing data in digital systems, enabling efficient processing and storage of diverse information types.