0% found this document useful (0 votes)
2 views

CH2- Data Representation

Chapter Two discusses data representation in computing, covering bits, bytes, words, and various number systems including binary, decimal, and hexadecimal. It explains fixed- and floating-point representations, as well as methods for representing negative integers. Additionally, the chapter addresses character data representation through ASCII and Unicode, highlighting their significance in modern computing.

Uploaded by

abel89935024
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

CH2- Data Representation

Chapter Two discusses data representation in computing, covering bits, bytes, words, and various number systems including binary, decimal, and hexadecimal. It explains fixed- and floating-point representations, as well as methods for representing negative integers. Additionally, the chapter addresses character data representation through ASCII and Unicode, highlighting their significance in modern computing.

Uploaded by

abel89935024
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

CHAPTER TWO

DATA REPRESENTATION

10/22/2024 1
Outline:

✓ Bits, bytes, and words

✓ Numeric data representation and number bases

✓ Fixed- and floating-point systems

✓ Signed and twos-complement representations

✓ Data types

✓ Representation of nonnumeric data (character codes, graphical data)

✓ Representation of records and arrays

10/22/2024 2
Bits, Bytes and Words

Bits
✓ A bit is a Binary digit. So a bit is a zero or a one.

✓ The bit is a basic unit of information used in computing and digital


communications.

✓ A binary digit can have only one of two values, 0 and 1.

✓ Bits can be implemented in computer hardware using switches.

10/22/2024 3
Cont’d…

Bytes
➢ A byte is a sequence of bits.

➢ A byte has been 8 bits in length.

Example: 01000001 is a byte.

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.

✓ There are 16 bits in a word.

✓ 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

➢In everyday life we use a system based on decimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) to

represent numbers and refer to the system as the decimal system.

Example: the number 83 means.

It means eight tens plus three: 83 = (8 * 10) + 3

➢The decimal system is said to have a base, or radix, of 10.

➢This means that each digit in the number is multiplied by 10 raised to a power

corresponding to that digit’s position:

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)

➢In general, for the decimal representation of

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

✓We use 16 different symbols,


✓The notation is called hexadecimal, and the 16 symbols are the hexadecimal digits.
✓It is used for representing integers, any sequence of binary digits, whether they
represent text, numbers, or some other type of data.
✓ The reasons for using hexadecimal notation are:
I. It is more compact than binary notation.
II. In most computers, binary data occupy some multiple of 4 bits, and
hence some multiple of a single hexadecimal digit.
III. It is extremely easy to convert between binary and hexadecimal.
Example: (110111100001)2 equivalent to (DE1)16

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).

➢ The sign-magnitude representation is complicated when performing arithmetic


operations.

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

According to this system:


✓ The positive number is represented the same way as in the sign-magnitude.
✓ But the negative number is represented using the b’s complement (b for base
numbers).
✓For example, the representation of the number (-19) using 2’s complement.
In this case, the number 19 is first represented as (010011).
Then each digit is complemented, hence the name radix complement to produce
(101100).
Finally a “1” is added at the least significant bit position to result in (101101).
✓Example2: consider the 2’s complement representation of the number (+18).
Since the number is positive, then it is represented as (010010), the same as in
the sign-magnitude case.
10/22/2024 14
Two’s Complement (2’s) Representation
To represent a number in 2’s complement, we perform the following two steps.
1. Perform the Boolean complement of each bit (including the sign bit);
2. Add 1 to the least significant bit (i.e. -A= A’+ 1)
Example: Consider the representation of (-22) using 2’s complement.
Solution: 22=00010110
11101001 1’s complement
+ 1
11101010 (-22)
The main advantage of the 2’s complement representation:
I. is that no special treatment is needed for the sign of the numbers.
II. If carry coming out of the most significant bit while performing
arithmetic operations is ignored without affecting the correctness of the
result (i.e. no effect in result!)
10/22/2024 15
Binary Addition

Rules for Binary Addition:

A+B SUM CARRY

0+0 0 0

0+1 1 0

1+0 1 0

1+1 0 1

10/22/2024 16
Binary Subtraction

Rules for Binary Subtraction:

A-B SUBSTRACT BORROW

0-0 0 0

0-1 1 1

1-0 1 0

1-1 0 0

10/22/2024 17
Binary Multiplication

Rules for Binary Multiplication:

A*B MULTIPLICATION

0X0 0

0X1 0

1X0 0

1X1 1

10/22/2024 18
Fixed- and Floating-Point Numbers

Fixed Point Number


➢A fixed point number consist of 3 parts:
✓a sign field,
✓specific number of bits (or digits) reserved for the integer part (the part to the left of
the decimal point) and
✓a specific number of bits reserved for the fractional part (the part to the right of the
decimal point).

➢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…

➢On a computer, 0 is used to represent + and 1 is used to represent – in sign field.


➢Ex: The 32-bit string : 1 | 000000000101011 | 1010000000000000

➢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

▪Figure 2.1 is a representation of a floating-point number having m = 23 bits, e= 8


bits, and S (sign bit)= 1 bit.
▪If the value stored in S is 0, the number is positive and if the value stored in S is 1,
the number is negative.
10/22/2024 21
Floating-Point Arithmetic Addition/Subtraction
❑The difficulty in adding two FP numbers stems from the fact that they may
have different exponents.
❑Therefore, before adding two FP numbers, their exponents must be equalized,
that is, the mantissa of the number that has smaller magnitude of exponent must
be aligned.
❑Steps Required to Add/Subtract Two Floating-Point Numbers
1. Compare the magnitude of the two exponents and make suitable
alignment to the number with the smaller magnitude of exponent.
2. Perform the addition/subtraction.
3. Perform normalization by shifting the resulting mantissa and adjusting the
resulting exponent.
10/22/2024 22
Example: consider adding the two FP numbers 1.1100*24 and 1.1000*22
1. Alignment: 1.1000 * 22 has to be aligned to 0.0110 * 24
2. Addition: Add the two numbers to get 10.0010 * 24.
3. Normalization: The final normalized result is 0.1000 * 26 (assuming 4 bits
are allowed after the radix point).
Multiplication:
Multiplication of a pair of FP numbers X = m x * 2a and Y = my * 2b is
represented as X * Y= (mx my) * 2a+b.
A general algorithm for multiplication of FP numbers consists of three basic
steps. These are:
1. Compute the exponent of the product by adding the exponents together.
2. Multiply the two mantissas.
3. Normalize and round the final product.
10/22/2024 23
Example: consider multiply the two FP numbers X=1.000*2-2 and Y=-1.010*2-1
Solution:

1. add exponents: -2+(-1) =-3


2. multiply the mantissas: 1.000*-1.010=-1.01000
Then the product is: -1.0100*2-3

Division:
❑ Division of a pair of FP numbers X=mx * 2a and Y= my * 2b is represented as

X/Y= (mx /my)* 2a-b.


❑A general algorithm for division of FP numbers consists of three basic steps:
1. Compute the exponent of the result by subtracting the exponents.
2. Divide the mantissa and determine the sign of the result.

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)

Character data is probably the most common data type encountered


besides integer Values.

The different characters includes: non printable characters called the


control characters, various punctuation symbols, special characters,
numeric digits; upper case and lower case alphabetic symbols etc.

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…

• Unicode can represent characters of different languages and is accepted

globally.

• It includes Chinese (traditional and simplified), English, French,

Amharic, Japanese, Korean and many others.

10/22/2024 28
10/22/2024
Table 2.1 The ASCII codes 29

You might also like