CH2- Data Representation
CH2- Data Representation
DATA REPRESENTATION
10/22/2024 1
Outline:
✓ Data types
10/22/2024 2
Bits, Bytes and Words
Bits
✓ A bit is a Binary digit. So a bit is a zero or a one.
10/22/2024 3
Cont’d…
Bytes
➢ A byte is a sequence of bits.
10/22/2024 4
Cont’d…
Words
✓ A word is the number of bits that are manipulated as a unit by the particular CPU of the computer.
✓ In computing, a word is the natural unit of data used by a particular processor design.
✓ A word is a fixed-sized piece of data handled as a unit by the instruction set or the hardware of the
processor.
Summary:
❖ 1 Bit – 0 or 1
❖ 1 Byte = 8 Bits
❖ 1 Word = 16 Bits or 2 Bytes
10/22/2024 5
Number Systems
➢ Most modern computer systems do not represent numeric values using the
decimal system.
➢ Numbering system uses a specific radix (base).
➢ Radices that are power of 2 are widely used in digital systems.
➢ These radices include:
Binary (base 2),
Quaternary (base 4),
Octagonal (base 8),
Decimal (base 10) and
Hexagonal (base 16).
➢ The base 2 binary system is dominant in computer systems.
10/22/2024 6
2.2The Decimal Number System
➢This means that each digit in the number is multiplied by 10 raised to a power
10/22/2024 7
Cont’d…
➢The same principle holds for decimal fractions but negative powers of 10 are
used.
➢Example: the decimal fraction 0.256 stands for 2 tenths plus 5 hundredths plus
6 thousandths (2*10-1 + 5*10-2 + 6*10-3)
The value of X is
10/22/2024 8
2.3 The Binary Number System
❖In the decimal system, 10 different digits are used to represent numbers with a
base of 10.
❖In the binary system, we have only two digits, 1 and 0.
❖Thus, numbers in the binary system are represented to the base 2.
❖In general, for the binary representation of
the value of Y is
❖Example: (1001.10001)2
10/22/2024 9
2.4 Hexadecimal Number System
10/22/2024 10
Negative Integer Representation
✓There exist a number of methods for representation of negative integers.
✓These includes:
▪ the sign-magnitude,
▪ the radix/base complement,
Sign-Magnitude
✓According to this representation,
The most significant bit (of the n bits used to represent the number) is used to
represent the sign of the number
If in the most significant bit position is “1”, it indicates a negative number
while a
If “0” in the most significant bit position, it indicates a positive number.
10/22/2024 11
➢ The remaining (n-1) bits are used to represent the magnitude of the number.
➢ Example:
the negative number (-18) is represented using 6 bits, base 2 in the sign-
magnitude format, as follows (110010),
while a (+18) is represented as (010010).
10/22/2024 12
Cont’d….
✓Example, the addition of the two numbers +18 (010010) and -19 (110011) using
the sign-magnitude representation.
✓Since the two numbers carry different signs, then the result should carry the sign
of the larger number in magnitude, in this case the (-19).
✓The remaining 5-bit numbers are subtracted (10011 - 10010) to produce (00001),
that is, (-1).
10/22/2024 13
Radix Complement
0+0 0 0
0+1 1 0
1+0 1 0
1+1 0 1
10/22/2024 16
Binary Subtraction
0-0 0 0
0-1 1 1
1-0 1 0
1-1 0 0
10/22/2024 17
Binary Multiplication
A*B MULTIPLICATION
0X0 0
0X1 0
1X0 0
1X1 1
10/22/2024 18
Fixed- and Floating-Point Numbers
➢It reserved 1 bit for sign field, 15 bits for the integer part and 16 bits for the fractional
part.
10/22/2024 19
Cont’d…
➢No matter how large or small your number is, it will always use the same number
of bits for each portion.
➢Example:
➢ Represents (−101011.101)2 = -43.5
10/22/2024 20
Floating-point representation and arithmetic
Floating-Point Representation:
▪A floating-point (FP) number can be represented in the following form:,
where m, called the mantissa, represents the fraction part of the number and is
normally represented as a signed binary fraction, e represents the exponent, and b
represents the base (radix) of the exponent.
Fig 2.1 Representation of a floating-point number
Division:
❑ Division of a pair of FP numbers X=mx * 2a and Y= my * 2b is represented as
10/22/2024
3. Normalize and round the resulting value, if necessary. 24
EXAMPLE: consider the division of two FP numbers X=1.000*2-2 and
Y= -1.0100*2-1
1. Subtract exponents: -2 - (-1)=-1.
2. Divide the mantissas: 1.0000/-1.0100= -0.1101.
3. The result is -0.1101* 2-1.
10/22/2024 25
Representation of non numeric data(character codes
and graphical symbols)
10/22/2024 26
So we use the ASCII to represent for those different characters in modern
programs.
ASCII uses 7-bits for character representation and it can only represent up to 128
separate character codes/ unique code.
But ASCII code can not represent for characters that have more than 128 bit
lengths
So in modern computer system it is being replaced by Unicode which is designed
to cope with many more character sets.
Unicode uses 16-bits.
10/22/2024 27
Cont’d…
globally.
10/22/2024 28
10/22/2024
Table 2.1 The ASCII codes 29