CSC 222: Computer Organization: & Assembly Language
CSC 222: Computer Organization: & Assembly Language
CSC 222: Computer Organization: & Assembly Language
2 – Data Representation
2
Positional Number System
A computer can understand positional number system where
there are only a few symbols called digits and these symbols
represent different values depending on the position they
occupy in the number.
3
Decimal Number System
4
Binary Number System
5
Hexadecimal Number System
6
Conversion Between Number Systems
Converting Hexadecimal to Decimal
Multiply each digit of the hexadecimal number from right to
left with its corresponding power of 16.
Convert the Hexadecimal number 82ADh to decimal number.
7
Conversion Between Number Systems
Converting Binary to Decimal
Multiply each digit of the binary number from right to
left with its corresponding power of 2.
Convert the Binary number 11101 to decimal number.
8
Conversion Between Number Systems
Converting Decimal to Binary
Divide the decimal number by 2.
Take the remainder and record it on the side.
REPEAT UNTIL the decimal number cannot be
divided into anymore.
9
Conversion Between Number Systems
Converting Decimal to Hexadecimal
Divide the decimal number by 16.
Take the remainder and record it on the side.
REPEAT UNTIL the decimal number cannot be
divided into anymore.
10
Conversion Between Number Systems
Converting Hexadecimal to Binary
Given a hexadecimal number, simply convert each digit to it’s binary equivalent.
Then, combine each 4 bit binary number and that is the resulting answer.
11
Binary Arithmetic Operations
Addition
Like decimal numbers, two numbers can be added by adding
each pair of digits together with carry propagation.
11001 647
+ 10011 + 537
101100 1184
12
Binary Arithmetic Operations
Subtraction
Two numbers can be subtracted by subtracting each pair of
digits together with borrowing, where needed.
11001 627
- 10011 - 537
00110 090
13
Hexadecimal Arithmetic Operations
Addition
Like decimal numbers, two numbers can be added by adding
each pair of digits together with carry propagation.
5B39
+ 7AF4
D62D
Hexadecimal Addition
14
HexaDecimal Arithmetic Operations
Subtraction
Two numbers can be subtracted by subtracting each pair of
digits together with borrowing, where needed.
D26F
- BA94
17DB
Hexadecimal Subtraction
15
MSB and LSB
16
Unsigned Integers
17
Signed Integers
Example:
00001010 = decimal 10
10001010 = decimal -10
18
19
One’s Complement
The one’s complement of an integer is obtained by
complementing each bit, that is, replace each 0 by a 1 and
each 1 by a 0.
20
2’s Complement
Negative integers are stored in computer using 2’s
complement.
To get a two’s complement by first finding the one’s
complement, and then by adding 1 to it.
Example
11110011 (one's complement of 12)
+ 00000001 (decimal 1)
11110100 (two's complement of 12)
21
Subtract as 2’s Complement Addition
Find the difference of 12 – 5 using complementation and
addition.
00000101 (decimal 5)
11111011 (2’s Complement of 5)
No Carry
22
Example
Find the difference of 5ABCh – 21FCh using
complementation and addition.
5ABCh = 0101 1010 1011 1100
21FCh = 0010 0001 1111 1100
1101 1110 0000 0100 (2’s Complement of 21FCh)
Discard
Carry
23
Decimal Interpretation
How to interpret the contents of a byte or word as a signed
and unsigned decimal integer?
Unsigned decimal interpretation
Simply just do a binary to decimal conversion or first convert
binary to hexadecimal and then convert hexadecimal to
decimal.
Signed decimal interpretation
If msb is zero then number is positive and signed decimal is
same as unsigned decimal.
If msb is one then number is negative, so call it -N. To find N,
just take the 2’s complement and then convert to decimal.
24
Example
Give unsigned and signed decimal interpretation FE0Ch.
Unsigned decimal interpretation
25
Decimal Interpretation
For 16 – bit word, following relationships holds between
signed and unsigned decimal interpretation
From 0000h – 7FFFh, signed decimal = unsigned decimal
From 8000h – FFFFh, signed decimal = unsigned decimal
– 65536.
Example:
Unsigned interpretation of FE0Ch is 65036.
Signed interpretation of FE0Ch = 65036 – 65536 = -500.
26
Binary, Decimal, and Hexadecimal Equivalents.
0000 0 0 1000 8 8
0001 1 1 1001 9 9
0010 2 2 1010 10 A
0011 3 3 1011 11 B
0100 4 4 1100 12 C
0101 5 5 1101 13 D
0110 6 6 1110 14 E
0111 7 7 1111 15 F
Character Representation
All data, characters must be coded in binary to be
processed by the computer.
ASCII:
American Standard Code for Information Interchange
Most popular character encoding scheme.
Uses 7 bit to code each character.
27 = 128 ASCII codes.
Single character Code = One Byte [7 bits: char code, 8 th bit set
to zero]
32 to 126 ASCII codes: printable
0 to 31 and 127 ASCII codes: Control characters
28
29
How to Convert?
If a byte contains the ASCII code of an uppercase letter,
what hex should be added to it to convert to lower case?
Solution: 20 h
Example: A (41h) a (61 h)
If a byte contains the ASCII code of a decimal digit, What
hex should be subtracted from the byte to convert it to the
numerical form of the characters?
Solution: 30 h
Example: 2 (32 h)
30
Character Storage
123
123 = 01111011
31