Download as pdf or txt
Download as pdf or txt
You are on page 1of 60

CHAPTER 2

Machine Level Representation Of


Data

Edited on Mac2020
LESSON OUTCOMES
Upon completion of this chapter, students should understand about:

• Numeric conversion between number bases


o Decimal ↔ Binary ↔ Octal ↔ Hexadecimal
• Frac2onal Conversions
• Signed Numbers Representa2on
o Sign-magnitude, 1s complement, 2s complement
• Arithme2c opera2ons
o AddiAon and SubtracAon
• Floa2ng point format
o IEEE 754 standard – single precision
Data Representation
Bytes
Bits Eight bits grouped together is
Each digit 0 or 1 is called a bit called a byte
Smallest unit of data that the Each character such as a
computer can represent letter or a number is
represented in a byte

Words Doubleword
16 bits grouped together is 32 bits grouped together is
called a word called a doubleword
Equivalent to 4 bytes

CSC159 | CHAPTER 2 |ZAZALEENA ZAKARIAH


Number System

system of system of
posiAonal notaAon posiAonal
based on powers DECIMAL BINARY notaAon based
of 10. on powers of 2.

system of system of
posiAonal notaAon HEXADEC
OCTAL posiAonal
based on powers IMAL notaAon based
of 8. on powers of 16
2.1 Numeric Conversion
BINARY NUMBERS

1 Only 2 voltage levels present in a digital


circuit – logic High (1) and logic Low (0).

Base 2: 0, 1
Converting Base 10 to Base 2
A decimal number 4210 can be converted to a
binary number by dividing the number by 2:
Converting Base 10 to Base 2
A decimal number 8710 can be converted to a
binary number by dividing the number by 2:
Converting Base 2 to Base 10
A binary number 11001112 is converted to a decimal numbers by
summing the weights of various positions in the binary number which
contains a 1.
BINARY NUMBERS : exercises
Convert the following number:

a) Decimal 23010 to binary


b) Binary 101101112 to decimal
BINARY NUMBERS : exercises
Convert the following number:

a) Decimal 31110 to binary


b) Binary 11011102 to decimal
OCTAL NUMBERS

1 The octal number uses base 8.

2 It uses the digits 0, 1, 2, 3, 4, 5,


6, 7
Converting Base 10 to Base 8
A decimal number 26610 can be converted to an octal number by
dividing the number by 8:
Converting Base 8 to Base 10
To convert an octal number 72638 to a decimal number, multiply
each octal value by the weight of the digit and sum the results.
Converting Base 8 to Base 10
To convert an octal number 3248 to a decimal number, multiply each
octal value by the weight of the digit and sum the results.
OCTAL NUMBERS
Each octal digit can be represented by a
3-bit binary number as shown below:

Octal Digits 3-bit Binary number

0 000
1 001
2 010
3 011
4 100
5 101
6 110
7 111
OCTAL NUMBERS
Each octal digit can be represented by a
3-bit binary number as shown below:
OCTAL NUMBERS
Each octal digit can be represented by a
3-bit binary number as shown below:
A binary number is converted into an octal number by taking groups of 3
bits, starting from LSB, and replacing them with an octal digit.
OCTAL NUMBERS
Each octal digit can be represented by a
3-bit binary number as shown below:
A binary number is converted into an octal number by taking groups of 3
bits, starting from LSB, and replacing them with an octal digit.
OCTAL NUMBERS : exercises
Convert the following number:

a) Decimal 24510 to octal


b) Octal 12538 to decimal
OCTAL NUMBERS : exercises
Convert the following number:

c) Octal 7648 to binary


d) Binary 110101112 to octal
OCTAL NUMBERS : exercises
Convert the following number:
a) Decimal 31110 to octal
b) Binary 11011102 to hexa
c) Octal 7348 to hexa
HEXADECIMAL NUMBERS

The hexadecimal number uses base 16.

1 It uses the digits 0 through 9 plus the


letters A, B, C, D, E and F.

2 The letter A stands for decimal 10, B for


11, C for 12, D for 13, E for 14 and F for
15.
HEXADECIMAL NUMBERS
Please refer to the table below:
Hexadecimal Decimal Binary

0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
A 10 1010
B 11 1011
C 12 1100
D 13 1101
E 14 1110
F 15 1111
Converting Base 10 to Base 16
A decimal number can be converted to hex number by
successively dividing the number by 16 as follows:
Converting Base 10 to Base 16
A decimal number can be converted to hex number by
successively dividing the number by 16 as follows:
HEXADECIMAL NUMBERS
To convert a hex number to a decimal number, multiply each hex value
by the weight of the digit and sum the results.
HEXADECIMAL NUMBERS
Conversion from hex to binary is very straightforward. Each hex
digit is replaced by 4-bit binary number.
HEXADECIMAL NUMBERS
Another example of the conversion: Hexadecimal à Binary
HEXADECIMAL NUMBERS
A binary number is converted into a hex number by taking groups of 4
bits, starting from LSB, and replacing them with a hex digit.
HEXADECIMAL NUMBERS
: exercises
Convert the following number:

a) Decimal 31510 to hexadecimal


b) Hexadecimal 6E916 to decimal
HEXADECIMAL NUMBERS
: exercises
Convert the following number:

c) Hexadecimal 24F16 to binary


d) Binary 10110100111012 to hexadecimal
Exercises
Convert the following number:

574 8 = 2 = 16 = 10
AF2 16 = 2 = 8 = 10
652 8 = 2 = 16 = 10
2.2 Fractional Conversions
Fractions

• Number point or radix point


♦Decimal point in base 10
♦Binary point in base 2
• No exact relaAonship between fracAonal
numbers in different number bases
♦Exact conversion may be impossible
Decimal Fractions

• Move the number point one place to the right


♦ Effect: mulAplies the number by the base number
♦ Example: 139.010 139010

• Move the number point one place to the le\


♦ Effect: divides the number by the base number
♦ Example: 139.010 13.910
Decimal Fraction
ConverAng Base 10 and Base 2
Decimal Fractions
Base 10 and Base 2

• No general relaAonship between fracAons of types 1/10k


and 1/2k
♦ Therefore a number representable in base 10 may
not be representable in base 2
♦ But: the converse is true: all fracAons of the form
1/2k can be represented in base 10
• FracAonal conversions from one base to another are
stopped
♦ If there is a raAonal soluAon or
♦ When the desired accuracy is aaained
Decimal Fractions
Mixed number conversion

• Integer and fracAon parts must be converted


separately
• Radix point: fixed reference for the conversion
♦Digit to the le\ is a unit digit in every base
♦B0 is always 1 regardless of the base
2.3 Representations for
signed integers
Complementary Representation

• We normally represent signed integers by a plus


or minus sign and a value
• In computers, we cannot use a sign symbol
♦ Must restrict to 0’s and 1’s
• RepresentaAon of signed numbers:
♦ Sign-and-magnitude
♦ 1s complement
♦ 2s complement
Sign and Magnitude Representation

• Represent signed integers by a plus or minus sign


and a value
• In computer, we cannot use a sign
♦Must restrict to 0’s and 1’s
• Example:
One’s Complement

• Numbers that begin with 0 are posiAve


• Numbers that begin with 1 are negaAve
• Performed by changing every 0 to 1 and
every 1 to 0 (inversion) à FLIP!
• Example:
Two’s Compliment
Find the 1’s complement and add 1 to the result. For example, 2’s complement of +2 in binary.
2.4 Arithmetic Operations
(addition and subtraction)
Addition
AddiAon in Octal

Carry Carry
1 1 1 1 1 1 1
4568 777148
+ 1238 + 768
6018 1000128
Remember!!
Digits in Octal are 0
to 7.
Addition
AddiAon in Hexadecimal

0
Carry
1 1

7A616 9
+ 2BA16 10
11
A
B
A6016 12 C
13 D
14 E
15 F
Addition
AddiAon in Binary

Carry Carry
1 1 0 1 1 1

1112 7 001112 7
+ 102 + 2 + 101012 +21
10012 9 111002 28
Subtraction
SubtracAon in Octal

+8 Borrow
2 4 +8
If you borrow
3568 3568 in Octal,
- 1578 - 1578 the value
borrowed
1778 1778 is 8.
Subtraction
SubtracAon in Hexadecimal

0
Borrow

B +16 9 +16

C9AD16 C9AD16 9
10 A
- 5A8F16 - 5A8F16 If you borrow
in Octal,
the value
11 B
12 C
6F1E16 6F1E16 borrowed
Is 16.
13 D
14 E
15 F
Subtraction
SubtracAon in Binary

Borrow

1 1
0 10 10 10
110002 110002
- 1112 - 1112 If you borrow
in Octal,
the value
100012 100012 Borrowed
is 210 or 10 .
2
2.5 Floating Point format (IEEE
754 standard single precision)
Floating Point
ScienAfic NotaAon

• In many calculaAons the range of numbers


used is very large.
• A number can be represented by using
scienAfic representaAon commonly used in
physics, chemistry, and engineering.
• The computer version of the scienAfic
notaAon is called floaAng point.
Floating Point
ScienAfic NotaAon
Floating Point
ScienAfic NotaAon
Floating Point
ScienAfic NotaAon
Floating Point
Example: Convert -23.675 to floaAng point numbers in IEEE. Give the result in hexadecimal.

Step 1: Convert to binary -23.675 = 10111.1012


Step 2: Put into 1.XXXX x 2y 1.01111012 x 24
Step 3: Get the sign Sign –ve = 1
Step 4: Get the biased exponent Exponent = 4
Biased exponent = 127 + 4 = 131
= 100000112
Step 5: Get the manAssa and ManAssa = 1.01111012
significand Significand = 0111 1010 0000 0000 0000
Step 6: Put into IEEE format sign Biased ManAssa / significand
exponent
1 10000011 0111 1010 0000 0000 0000
Step 7: Convert to hexadecimal 1100 0001 1011 1101 0000 0000 0000 0000
C 1 B D 0 0 0 0
EXCERCISE
EXCERCISE
Convert the following numbers to IEEE single precision format in hexadecimal form:

You might also like