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

02 MLRepresentationOfData

The document discusses machine-level representation of data, including: 1) Converting between different numeric bases such as decimal, binary, octal, and hexadecimal. 2) Representing fractions in different bases and the limitations of exact conversions. 3) Complementary representations of signed numbers using sign-magnitude, one's complement, and two's complement methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

02 MLRepresentationOfData

The document discusses machine-level representation of data, including: 1) Converting between different numeric bases such as decimal, binary, octal, and hexadecimal. 2) Representing fractions in different bases and the limitations of exact conversions. 3) Complementary representations of signed numbers using sign-magnitude, one's complement, and two's complement methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Machine Level

Representation
of Data
CSC159 – Computer Organization
Lesson Outcomes
 Numeric conversion between number bases
 Decimal ↔ Binary ↔ Octal ↔ Hexadecimal
 Fractional Conversions
 Signed Numbers Representation
 Sign-magnitude, 1s complement, 2s complement
 Arithmetic operations
 Addition and Subtraction
 Floating point format
 IEEE 754 standard – single precision

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 2


Number System
 Number system is based on positional
notation (place value)
 Decimal system: system of positional notation based on
powers of 10.
 Binary system: system of positional notation based
powers of 2
 Octal system: system of positional notation based on
powers of 8
 Hexadecimal system: system of positional notation
based powers of 16

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 3


Number System (cont.)
 Decimal or base 10 number system
 Origin: counting on the fingers
 “Digit” from the Latin word digitus meaning “finger”
 Base: the number of different digits including
zero in the number system
 Example: Base 10 has 10 digits, 0 through 9
 Binary or base 2 1 byte = 8-bit
1 word = ?
 Bit (binary digit): 2 digits, 0 and 1

 Octal or base 8: 8 digits, 0 through 7


 Hexadecimal or base 16: 16 digits, 0 through F

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 4


Number System (cont.)
 Base or Radix
 The number of different symbols required to
represent any given number
 The larger the base, the more numerals are
required but the fewer digits needed
 Base 10: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
 Base 2: 0, 1
 Base 8: 0, 1, 2, 3, 4, 5, 6, 7
 Base 16: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 5


Converting from Base 10
 Powers Table

8 7 6 5 4 3 2 1 0

2 256 128 64 32 16 8 4 2 1

8 32,768 4,096 512 64 8 1

16 65,536 4,096 256 16 1

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 6


From Base 10 to Base 2
Base 10 42 Remainder

Quotient 2 ) 42 ( 0 Least significant bit


2 ) 21 ( 1
2 ) 10 ( 0
2) 5 (1
2) 2 (0
2) 1 Most significant bit
Base 2 101010
UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 7
From Base 10 to Base 16
5,73510 = 166716
Power
4 3 2 1 0
Base

16 65,536 4,096 256 16 1

1 6 6 7
Integer 5,735 /4,096 1,639 / 256 103 /16 7
=1 =6 =6
Remainder 5,735 - 4,096 1,639 –1,536 103 – 96
= 1,639 = 103 =7

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 8


From Base 10 to Base 16
Base 10 5,735 Remainder

Quotient 16 ) 5,735 ( 7 Least significant bit


16 ) 358 ( 6
16 ) 22 ( 6
16 ) 1 ( 1 Most significant bit
16 ) 0
Base 16 1667

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 9


From Base 10 to Base 16
Base 10 8,039 Remainder

Quotient 16 ) 8,039 ( 7 Least significant bit


16 ) 502 ( 6
16 ) 31 ( 15
16 ) 1 ( 1 Most significant bit
16 ) 0
Base 16 1F67

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 10


From Base 8 to Base 10
72638 = 3,76310
Power 83 82 81 80

512 64 8 1

x7 x2 x6 x3
Sum for
Base 10 3,584 128 48 3

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 11


From Base 8 to Base 10
72638 = 3,76310
7
x8
56 + 2 = 58
x8
464 + 6 = 470
x8
3760 + 3 = 3,763

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 12


From Base 16 to Base 2
 The nibble approach
 Hex easier to read and write than binary

Base 16 1 F 6 7

Base 2 0001 1111 0110 0111


 Why hexadecimal?
 Modern computer operating systems and networks
present variety of troubleshooting data in hex
format

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 13


Fractions
 Number point or radix point
 Decimal point in base 10
 Binary point in base 2
 No exact relationship between fractional
numbers in different number bases
 Exact conversion may be impossible

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 14


Decimal Fractions
 Move the number point one place to the right
 Effect:
multiplies the number by the base number
 Example: 139.010 139010
 Move the number point one place to the left
 Effect:
divides the number by the base number
 Example: 139.010 13.910

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 15


Fractions: Base 10 and Base 2
.258910
Place 10-1 10-2 10-3 10-4
Value 1/10 1/100 1/1000 1/10000
Evaluate 2 x 1/10 5 x 1/100 8 x 1/1000 9 x1/1000
Sum .2 .05 .008 .0009

.1010112 = 0.67187510

Place 2-1 2-2 2-3 2-4 2-5 2-6

Value 1/2 1/4 1/8 1/16 1/32 1/64

Evaluate 1 x 1/2 0 x 1/4 1x 1/8 0 x 1/16 1 x 1/32 1 x 1/64

Sum .5 0.125 0.03125 0.015625

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 16


Fractions: Base 10 and Base 2
 No general relationship between fractions
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 fractions of the
form 1/2k can be represented in base 10
 Fractional conversions from one base to
another are stopped
 If
there is a rational solution or
 When the desired accuracy is attained

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 17


Mixed Number Conversion
 Integer and fraction parts must be converted
separately
 Radix point: fixed reference for the
conversion
 Digit to the left is a unit digit in every base
 B0 is always 1 regardless of the base

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 18


Complementary Representations
 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
 Representation of signed numbers:
 Sign-and-magnitude
 1s complement
 2s complement

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 19


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: +ve value -ve value
+1 00000001 -1 10000001
+2 00000010 -2 10000010
+3 00000011 -3 10000011
+4 00000100 -4 10000100
+5 00000101 -5 10000101

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 20


One’s Complement
 Numbers that begin with 0 are positive
 Numbers that begin with 1 are negative
 Performed by changing every 0 to 1 and every
1 to 0 (inversion) FLIP!
 Example: +ve value -ve value
+1 00000001 -1 11111110
+2 00000010 -2 11111101
+3 00000011 -3 11111100
+4 00000100 -4 11111011
+5 00000101 -5 11111010

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 21


Two’s Complement
 Find the 1’s complement and add 1 to the result
 Example, find the 2’s complement of +2 in
binary:
+2 = 000000102 , -2 = ?
2’s complement:
1) Find 1’s complement
00000010 (flip)
11111101
2) Add 1
11111101
+ 1
11111110 = -2
UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 22
Floating Point (Scientific Notation)
 In many calculations the range of numbers used
is very large
 A number can be represented by using scientific
representation commonly used in physics,
chemistry, and engineering
 The computer version of the scientific notation is
called floating point

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 23


Floating Point (Scientific Notation)
Example (Decimal):
1. 523.467 = 52.3467 x 101
2. 3417000000000000 = 3.417 x 1015
3. - 0.000000001234 = - 1.234 x 10-9

Example (binary):
1. -10000.1 = -100.001 x 22
= -1.00001 x 24
2. 0.000101 = 1.01 x 2-4
UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 24
Floating Point (Scientific Notation)

number = m x a e
m – mantissa
a – base
e – exponent (positive or negative integer)

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 25


Floating Point (Scientific Notation)
 Single precision format uses 32-bit

SIGN EXPONENT SIGNIFICAND

< 1-bit > <8-bit > < 23-bit >

 Double precision format uses 64-bit


< 1-bit > < 11-bit > < 52-bit>

UiTM Terengganu
Topic 2: Machine Level Representation of Data
26
- naza
Floating Point (Scientific Notation)

 Sign  0 = positive , 1 = negative

 Exponent  excess-127 (single precision)

 Significand  similar to mantissa but with


an implied 1 bit, an implied binary point,
followed by the rest of the fraction

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 27


IEEE 754 format
(single-precision floating point)

Step 1 - Convert to binary


Step 2 - Put into 1.xxxx X 2y
Step 3 - Get the sign
Step 4 - Get the biased exponent
Step 5 - Get the mantissa & the
significand
Step 6 - Put into IEEE format Sign Biased Mantissa /
Exponent significand

1-bit 8-bit 23-bit


Step 7 - Convert to hexadecimal

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 28


Exercise
1. Represent the decimal value 15.25 using
32-bit IEEE single precision format in
hexadecimal form.

2. Convert BBE0000016 IEEE single precision


floating point number to its decimal value.

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 29


Convert the following numbers to IEEE single
precision format in hexadecimal form:

a) 1011110.100012
b) 0.0000000000110112
c) -712.510

UiTM Terengganu - naza Topic 2: Machine Level Representation of Data 30

You might also like