Professional Documents
Culture Documents
Computer Organization - Data Representation On CPU
Computer Organization - Data Representation On CPU
0:
Topic Cover
2.1
2.2
2.3
2.4
Number System (decimal, binary, octal, and hexadecimal) Arithmetic Operation in number system. Convert Decimal, Binary, Octal and Hexadecimal Numbers to different bases. Coding system:
Sign and magnitude, 1s Complement and 2s Complement Binary Coded Decimal (BCD system) ASCII and EBCDIC
INTRODUCTION
Examples
Real World Data Input device Computer Data
Dear Mom:
Keyboard
10110010
Digital camera
10110010
Decimal
number system
10 Symbol
Example: 23410
Multiplier: 103 = 1000 102 = 100 101 = 10 100 =1 . . 10-1 = 0.1
Example:
2746.210
This number is came from this calculation:
2
103 = 1000
7
102 = 100
4
101 = 10
2
100 =1
.
. .
2
10-1 = 0.1
2746.210 = (2x1000) + (7x100) + (4x10) + (2x1) + (2x0.1) = 2000 + 700 + 40 + 2 + 0.2 = 2746.2 Decimal number = Natural Number
Arithmetic Operation
Decimal
Decimal Addition
Example:
b. 75710 + 24510 =
Decimal Subtraction
Example: a. 5410 - 1710 = 5410 - 1710 3710 Try this : 533310 - 3710 = ?
b. 15710 - 8910 =
Octal
number system
8 Symbol
Example: 658
Multiplier: 83 = 512 82 = 64 81 =8 80 =1 . . 8-1 = 0.125
Example:
107.158
This number can be convert to decimal value using this calculation:
1
82 = 64
0
81 =8
7
80 =1
.
. .
1
8-1 = 0.1250
5
8-2 = 0.0156
107.158
Arithmetic Operation
Octal
Octal Addition
Sekiranya setiap hasil perjumlahan yang melebihi atau sama dengan 8 mestilah ditolak dengan 8. Example: a. 1238 + 3218 = 1238 +3218 4448
b. 4578 + 2458 =
Octal Subtraction
Sekiranya terdapat peminjam, nombor peminjam mestilah dijumlahkan dengan 8. Example: a. 5248 - 1678 = 5248 - 1678 3358
b. 1678 - 248 =
Binary
number system
2 Symbol
Example: 1012
Multiplier: 25 = 32 24 = 16 23 =8 22 =4 21 =2 20 =1
Example:
10.1012
This number can be convert to decimal value using this calculation:
1
21 =2
0
20 =1
.
. .
1
2-1 = 0.5000
0
2-2 = 0.2500
1
2-3 = 0.1250
10.1012
Arithmetic Operation
Binary
Binary Addition
The four basic rules for adding binary digits are as follows: 0+0=0 0+1=1 1+0=1 1 + 1 = 0 carry 1 Example: 110112 + 100012 = 110112 + 100012 1011002 Try this : 101112 + 1112 = ?
Binary Subtraction
The four basic rules for subtracting binary digits are as follows:0-0=0 0 - 1 = 1 borrow 1 1-0=1 1-1=0 Example:
10012 -102 =
10012 102 1112 Try this : 1010112 11112 =?
Binary Subtraction
Have previously looked at the subtraction operation. A quick review. Just like subtraction in any other base 10110 -10010 00100 And when a borrow is needed. Note that the borrow gives us 2 in the current bit position.
Example
In General
When there is no borrow into the msb position, then the subtrahend in not larger than the minuend and the result is positive and correct.
If a borrow into the msb does occur, then the subtrahend is larger than the minuend.
Consider
Now do the operation 4 6
Correct difference is -2 or -0010 Different because 2n was brought in and made the operation MN+2n
Hexadecimal
number system
16 Symbol
Example: 7A16
Multiplier: 163 = 4096 162 = 256 161 = 16 160 =1 . . 16-1 = 0.0626
Example:
B6F.7C16
This number can be convert to decimal value using this calculation:
B
162 = 256
6
161 = 16
F
160 =1
.
. .
7
16-1 0.0625
C
16-2 = 0.0039
B6F.7C16
= 2927.484310
Arithmetic Operation
Hexadecimal
Hexadecimal Addition
Sekiranya setiap hasil perjumlahan yang melebihi atau sama dengan 16 mestilah ditolak dengan 16. Example: a. 3316 + 4716 = 3316 + 4716 7A16 Try this : DF16 + AB16 = ?
b. 20D316 + 12BC16 =
Hexadecimal Subtraction
Nilai yang kecil daripada 16 boleh dipinjam dari sebelah dengan nilai 16. Example: a. 4416 - 1716 = 4416 - 1716 2D16 Try this : DF16 - AB16 = ?
b. 20D316 - 12BC16 =
2.3: Convert Decimal, Binary, Octal and Hexadecimal Numbers to different bases
1111012 This number can be convert to decimal value using this calculation: 1 1 1 1 0 1
25 = 32 24 = 16 23 =8 22 =4 21 =2 20 =1
1111012
1
22 =4
1
21 =2
1
20 =1
1
22 =4
0
21 =2
1
20 =1
01012 0
23 =8
1
22 =4
0
21 =2
1
20 =1
181 0
1 0 0
1810
= 100102
300
8
8 8
37
4 0
4
5 4
454
300.3410 = 454.256058
Try this: Convert 32.20210 to Octal?
2010= 1416
Try this: Convert 343410 to hexadecimal?
MSB
4 58 0
20 =1
LSB
1
22 =4
0
21 =2
1
22 =4
0
21 =2
1
20 =1
1012
MSB
3 A16 1
21 =2
LSB
0
23 =8
0
22 =4
1
20 =1
1
23 =8
0
22 =4
1
21 =2
0
20 =1
0011 10102
+126
+125
01111110
01111101
+1 0 -1 -2
-127 -128
Sign Bit
What did do you notice about the most significant bit of the binary numbers? The MSB is (0) for all positive numbers. The MSB is (1) for all negative numbers. The MSB is called the sign bit. In a signed number system, this allows you to instantly determine whether a number is positive or negative.
+127 01111111 pos(+)
+126
+125
01111110
01111101
+1 0 -1 -2
-127 -128
1s Complement
This is just inverting each bit.
0000010
flip the number.
1 1 11 1 0 1
2S Complement Process
The steps in the 2s Complement process First, complement all of the digits in a number.
A digits complement is the number you add to the digit to make it equal to the largest digit in the base (i.e., 1 for binary). In binary language, the complement of 0 is 1, and the complement of 1 is 0.
Second, add 1.
Without this step, our number system would have two zeroes (+0 & -0), which no number system has.
2s Complement Examples
Example #1
5 = 00000101 11111010
+1 Complement Digits
-5 = 11111011
Add 1
Example #2
-13 = 11110011 00001100
+1 Complement Digits
13 = 00001101
9 + 5 14
(-9) + 5 -4
9 + (-5) 4
(-9) + (-5) -4
9 + 5 14
9 + (-5) 4
2s Complement Process
(-9) + 5 -4
11111100 00000011 +1 00000100
2s Complement Process
Digit
Bit pattern
0
1 2 3 4 5 6 7 8 9
0000
0001 0010 0011 0100 0101 0110 0111 1000 1001
Example
709310 = ? (in BCD) 7 0 9 3
ASCII
ASCII = American National Standard Code for Information Interchange 7-bit code 8th bit is unused (or used for a parity bit) 27 = 128 codes Two general types of codes:
95 are Graphic codes (displayable on a console) 33 are Control codes (control features of the console or communications channel)
ASCII Chart
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 000 NULL SOH STX ETX EDT ENQ ACK BEL BS HT LF VT FF CR SO SI 001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US 010 ! " # $ % & ' ( ) * + , . / 011 0 1 2 3 4 5 6 7 8 9 : ; < = > ? 100 @ A B C D E F G H I J K L M N O 101 P Q R S T U V W X Y Z [ \ ] ^ _ 110 ` a b c d e f g h i j k l m n o 111 p q r s t u v w x y z { | } ~ DEL
000 001 0000 NULL DLE 0001 SOH DC1 0010 STX DC2 0011 ETX DC3 0100 EDT DC4 0101 ENQ NAK 0110 ACK SYN 0111 BEL ETB 1000 BS CAN 1001 HT EM 1010 LF SUB 1011Least significant ESC VT bit 1100 FF FS 1101 CR GS 1110 SO RS 1111 SI US
010
100 @ A B C D E F G H I J K L M N O
101 P Q R S T U V W X Y Z [ \ ] ^ _
110 ` a b c d e f g h i j k l m n o
111 p q r s t u v w x y z { | } ~ DEL
e.g., a = 1100001
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
100 @ A B C D E F G H I J K L M N O
101 P Q R S T U V W X Y Z [ \ ] ^ _
110 ` a b c d e f g h i j k l m n o
111 p q r s t u v w x y z { | } ~ DEL
95 Graphic codes
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
100 @ A B C D E F G H I J K L M N O
101 P Q R S T U V W X Y Z [ \ ] ^ _
110 ` a b c d e f g h i j k l m n o
111 p q r s t u v w x y z { | } ~ DEL
33 Control codes
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
100 @ A B C D E F G H I J K L M N O
101 P Q R S T U V W X Y Z [ \ ] ^ _
110 ` a b c d e f g h i j k l m n o
111 p q r s t u v w x y z { | } ~ DEL
Alphabetic codes
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
100 @ A B C D E F G H I J K L M N O
101 P Q R S T U V W X Y Z [ \ ] ^ _
110 ` a b c d e f g h i j k l m n o
111 p q r s t u v w x y z { | } ~ DEL
Numeric codes
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
100 @ A B C D E F G H I J K L M N O
101 P Q R S T U V W X Y Z [ \ ] ^ _
110 ` a b c d e f g h i j k l m n o
111 p q r s t u v w x y z { | } ~ DEL
Punctuation, etc.
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
100 @ A B C D E F G H I J K L M N O
101 P Q R S T U V W X Y Z [ \ ] ^ _
110 ` a b c d e f g h i j k l m n o
111 p q r s t u v w x y z { | } ~ DEL
The Problem
Representing text strings, such as Hello, world, in a computer
H e l l o , w o r l d
= = = = = = = = = = = =
= = = = = = = = = = = =
= = = = = = = = = = = =
EBCDIC
Extended BCD Interchange Code (pronounced ebb-se-dick) 8-bit code Developed by IBM Rarely used today IBM mainframes only
Message below are represented in EBCDIC code. What is the message? Please convert by using EBCDIC Code table given: