Title | 02. Machine Level Representation OF DATA |
---|---|
Course | Computer Organization |
Institution | Universiti Teknologi MARA |
Pages | 15 |
File Size | 1.7 MB |
File Type | |
Total Downloads | 6 |
Total Views | 144 |
02. Machine Level Representation OF DATA...
LESSON OUTCOMES Upon completion of this chapter, students should understand about:
CHAPT Machine Level Representation Of Data
• 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&
Edited&on&Mac2020&
Data Representation
Number System
Bytes Bits Each digit 0 or 1 is called a bit Smallest unit of data that the computer can represent
Eight bits grouped together is called a byte Each character such as a letter or a number is represented in a byte
Words 16 bits grouped together is called a word
Doubleword 32 bits grouped together is called a doubleword Equivalent to 4 bytes
CSC159&|&CHAPTER&2&|ZAZALEENA&ZAKARIAH&
system&of& posiAonal¬aAon& based&on&powers& of&10.&
DECIMAL
BINARY
system&of& posiAonal¬aAon& based&on&powers& of&8.&
OCTAL
HEXADEC IMAL
system&of& posiAonal& notaAon&based& on&powers&of&2.&
system&of& posiAonal& notaAon&based& on&powers&of&16&
BINARY NUMBERS
Only 2 voltage levels present in a digital circuit – logic High (1) and logic Low (0).
2.1 Numeric Conversion
Converting Base 10 to Base 2 A decimal number 4210 can be converted to a binary number by dividing the number by 2:
Base 2: 0, 1
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
BINARY NUMBERS : exercises Convert the following number: a) Decimal 23010 to binary b) Binary 101101112 to decimal
OCTAL NUMBERS
Convert the following number: a) Decimal 31110 to binary b) Binary 11011102 to decimal
The octal number uses base 8.
It uses the digits 0, 1, 2, 3, 4, 5, 6, 7
Converting Base 10 to Base 8
Converting Base 8 to Base 10
A decimal number 26610 can be converted to an octal number by dividing the number by 8:
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
OCTAL NUMBERS
To convert an octal number 3248 to a decimal number, multiply each octal value by the weight of the digit and sum the results.
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
OCTAL NUMBERS
Each octal digit can be represented by a 3-bit binary number as shown below:
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
OCTAL NUMBERS : exercises
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.
Convert the following number:
a) Decimal 24510 to octal b) Octal 12538 to decimal
OCTAL NUMBERS : exercises
OCTAL NUMBERS : exercises
Convert the following number:
c) Octal 7648 to binary d) Binary 110101112 to octal
HEXADECIMAL NUMBERS
Convert the following number: a) Decimal 31110 to octal b) Binary 11011102 to hexa c) Octal 7348 to hexa
HEXADECIMAL NUMBERS Please refer to the table below:
1 2
The hexadecimal number uses base 16. It uses the digits 0 through 9 plus the letters A, B, C, D, E and F.
The letter A stands for decimal 10, B for 11, C for 12, D for 13, E for 14 and F for 15.
Hexadecimal
Decimal
Binary
0 1 2 3 4 5 6 7 8 9 A B C D E F
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Converting Base 10 to Base 16
Converting Base 10 to Base 16
A decimal number can be converted to hex number by successively dividing the number by 16 as follows:
A decimal number can be converted to hex number by successively dividing the number by 16 as follows:
HEXADECIMAL NUMBERS
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.
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 grou bits, starting from LSB, and replacing them with a hex digit
HEXADECIMAL NUMBERS : exercises
HEXADECIMAL NUMBERS : exercises
Convert the following number:
Convert the following number:
a) Decimal 31510 to hexadecimal b) Hexadecimal 6E916 to decimal
c) Hexadecimal 24F16 to binary d) Binary 10110100111012 to hexadecimal
Exercises Convert the following number:
574 8 = AF2 16 = 652 8 =
2 = 2 = 2 =
16 = 8 = 16 =
10 10 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:÷s&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&& &&&&&&&&&&¬&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®ardless&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&
One’s 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:&
Two’s Compliment Find&the&1’s&complement&and&add&1&to&the&result.&For&example,&2’s&complement&of&+2&in&binary.&&
• 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:&
Addition AddiAon&in&Octal&
Carry&
2.4 Arithmetic Operations (addition and subtraction)
Carry&
1&&&1&
&&&&4568& +&&1238& &&&&6018&
1&&&1&&&&&1&&&&1&&&1&
&&&&&&777148& +&&&&&&&&&&&768& &&&&1000128& Remember!!& Digits&in&Octal&are&0& to&7.&
Addition
Addition
AddiAon&in&Hexadecimal&
AddiAon&in&Binary&
0& Carry& Carry&
1&&&1&
&&&&7A616& +&&2BA16& &&&&A6016&
1&&&1&
9& 10& A& 11& B& 12& C& 13& D& 14& E& 15& F&
&&&&1112& +&&&&102& &&10012&
Carry& 0&&&&1&&&&1&&&&1&
&&&&7& &&&&001112& +&&2& +&&101012& &&&&9& &&&&111002&
&&&&7& +21& &&28&
Subtraction
Subtraction
SubtracAon&in&Octal&
SubtracAon&in&Hexadecimal&
0&
Borrow& +8& &&&2&&&&4&&&+8&
Borrow&
If&you&borrow & in&Octal,& the&value&& borrowed& is&8.&
&&&&3568& &&&& 68& -&&&1578& -&&&1578& &&&&1778& &&&&1778&
&B&&+16&&9&&&+16&
&&&&C9AD16& &&&& 9 D16& -&&&5A8F16& -&&&5A8F16& &&&&6F1E16& &&&&6F1E16&
If&you&borrow& in&Octal,& the&value&& borrowed& Is&16.&
9& 10& A& 11& B& 12& C& 13& D& 14& E& 15& F&
Subtraction SubtracAon&in&Binary&
Borrow&
2.5 Floating Point format (IEEE 754 standard single precision)
1&&&1& 0&&&
&&10&
&&&&110002& &&&&11 02& -&&&&&&&1112& -&&&&&&&1112& &&&&100012& &&&&100012&
If&you&borrow & in&Octal,& the&value&& Borrowed& is&210&or&10 .& 2
Floating Point ScienAfic&NotaAon&&
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&&
EXCERCISE
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& significand&
ManAssa&=&1.01111012& Significand&=&0111&1010&0000&0000&0000&
Step&6:&Put&into&IEEE&format&
sign& Biased& exponent&
ManAssa&/&significand&
1&
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&
10000011&
EXCERCISE& Convert&the&following&numbers&to&IEEE&single&precision&format&in&hexadecimal&form:&...