MACHINE LEVEL REPRESENTATION OF DATA (Part 1)
Prepared by: Nor Fauziah Binti Abu Bakar, FSKM
Contents
Bits, bytes, and words 2. Numeric data representation and number bases Binary, Octal, Hexadecimal 3. Conversion between bases
1.
Bits, Bytes, and Words
Bits
The basic unit of information in computing and
telecommunication In computing, a bit is defined as a variable or computed quantity that can have only two possible These two values are often interpreted as binary digits and are usually denoted by 0 and 1 In several popular programming languages, numeric 0 is equivalent (or convertible) to logical false, and 1 to true. The correspondence between these values and the physical states of the underlying storage or device is a matter of convention, and different assignments may be used even within the same device or program
Bits, Bytes, and Words - cont
Bytes
a unit of digital information in computing and
telecommunications, that most commonly consists of eight bits a byte was the number of bits used to encode a single character of text in a computer and it is for this reason the basic addressable element in many computer architectures. The byte size and byte addressing are often used in place of longer integers for size or speed optimizations in microcontrollers and CPUs
Bits, Bytes, and Words - cont
Words
In computing, word is a term for the natural unit of data
used by a particular computer design A word is simply a fixed sized group of bits that are handled together by the system The number of bits in a word (the word size or word length) is an important characteristic of computer architecture. The size of a word is reflected in many aspects of a computer's structure and operation; the majority of the registers in the computer are usually word sized and the amount of data transferred between the processing part computer and the memory system, in a single operation, is most often a word
NUMBERING SYSTEM :
PLACE BASE
5TH PLACE
105
4TH PLACE
104 10,000
3RD PLACE
103 1,000
2ND PLACE
102 100
1ST PLACE
101 10
SINGLE UNIT
100 1
1ST PLACE
10-1 0.1 1/10
2ND PLACE
10-2 0.01 1/100 2-2 0.25 1/4 8-2 0.015625 1/64 16-2 3.906 X 103 1/256
3RD PLACE
10-3 0.001 1/1000 2-3 0.125 1/8 8-3 1.953125 X 103 1/512 16-3 2.441406 2 X 104 1/4096
DECIMAL
100,000
25 BINARY 32
24 16
23 8
22 4
21 2
20 1
2-1 0.5 1/2
85 OCTAL 32,768
84 4,096
83 512
82 64
81 8
80 1
8-1 0.125 1/8
165 HEXADECIMAL 1,048,57 6
164 65,536
163 4,096
162 256
161 16
160 1
16-1 0.0625 1/16
Number Bases
Radix : when referring to binary, octal, decimal,
hexadecimal, a single lowercase letter appended to the end of each number to identify its type. E.g. hexadecimal 45 will be written as 45h octal 76 will be written as 76o or 76q binary 11010011 will be written as 11010011b
Number System
The following table shows the equivalent values for decimal numbers in binary, octal and hexadecimal:
Number System
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
Number System
Base:
The number of different symbols required to represent any
given number
The larger the base, the more numerals are required
Base 10: Base 2: Base 8:
Base 16 :
0,1, 2,3,4,5,6,7,8,9 0,1 0,1,2, 3,4,5,6,7 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
For a given number, the larger the base
the more symbols required
but the fewer digits needed
Number System
EXAMPLE:
Example #1:
6516 10110 Example #2: 11C16 28410
1458 4348
110 01012 1 0001 11002
Binary System
WHY??
Early computer design was decimal
Mark I and ENIAC
John von Neumann proposed binary data processing (1945)
Simplified computer design Used for both instructions and data
Natural relationship between
on/off switches and calculation using Boolean logic
On True Yes
Off False No
Binary System
A computer stores both instructions and data as
individual electronic charges.
represent these entities with numbers requires a system
geared to the concept of on and off or true and false
Binary is a base 2 numbering system
each digit is either a 0 (off) or a 1 (on)
Computers store all instructions and data as
sequences of binary digit
e.g. 010000010100001001001000011 = ABC
Binary System
Each digit in binary number has a value depending on its
position Example:
The number 1002 means
(1 X 2) + ( 0 X 2) + (0 X 2)
4+0+0 4
Base 2
7/21/2013
15
Decimal System
Decimal is a base 10 numbering system
We use a system based on decimal digits to represent
numbers Each digit in the number is multiplied by 10 raised to a power corresponding to that digit position. Example : The number 472810 means : (4 X 1000) + (7 X 100) + (2 X 10) + 8 4000 + 700 + 20 +8 4728
Base 10
7/21/2013
17
Octal System
As known as base 8 numbering system
There are only eight different digits available (0, 1, 2, 3,
4, 5, 6, 7) Example :
The number 7238 means (7 X 8) + (2 X 8) + (3 X 8) 448 + 16 + 3 467
Base 8
7/21/2013
19
Hexadecimal System
Hexadecimal is a base 10 numbering system
Used not only to represent integers Also used to represent sequence of binary digits
Example : The number 2C16 means: (2 X 16) + (C X 16) 32+ 12 44
Base 16
7/21/2013
21
Conversion Between Bases
1. Conversion of decimal to binary 2. Conversion of decimal to octal 3. Conversion of decimal to hexadecimal 4. Conversion of binary to decimal 5. Conversion of binary to octal 6. Conversion of binary to hexadecimal 7. Conversion of octal to decimal 8. Conversion of octal to binary 9. Conversion of hexadecimal to binary 10.Conversion of hexadecimal to decimal
CONVERSION : DECIMAL OTHER BASES
From Base 10 to Base 2
Base 10 Quotient 2) 42 Remainder 42 ( 0 Least significant bit
2) 2) 2) 2) 2)
Base 2
21 10 5 2 1 0
(1 (0 (1 (0 (1
101010
Most significant bit
From Base 10 to Base 2
Convert 3710 to binary.
37 2 18 2 92 42 22 12 = = = = = = 18 9 4 2 1 0 balance balance balance balance balance balance 1 0 1 0 0 1 (LSB)
(MSB)
Therefore , 3710 = 1001012
* MSB (most-significant-bit) : left most bit LSB (least-significant-bit) : right most bit
From Base 10 (decimal point) to Base 2
What is the value of 37.687510 in binary? Steps : 1. Convert the integer to binary by using method shown in previous slide. 2. Convert the decimal point to binary by using the following 0.6875 method.
X (MSB) 1 0 1 (LSB) 1 2 1.3750 X 2 0.7500 X 2 1.5000 X 2 1.0000 The 1 is saved as result, then dropped and the process repeated
So, (0.6875)10 = (0.1011)2 ; Therefore, 37.687510 = 100101.10112
From Base 10 to Base 8
Base 10 135 Remainder 135 ( 7 Least significant bit 16 ( 0 2 ( 2 Most significant bit 0 Base 8 207
Quotient
8) 8) 8)
From Base 10 (decimal point) to Base 8
Convert 21.2510 to octal. 8 21 8 2 0 5 2 2 0.25 8 2.00
Therefore, 21.2510
25.28
From Base 10 (decimal point) to Base 8
Convert 21.2510 to octal. (OTHER METHOD)
21 2 = 10 10 2 = 5 52 = 2 22 = 1 12 = 0 So, 2110 = 101012
balance balance balance balance balance
1 0 1 0 1
(LSB)
Now, (MSB) 0 1
(MSB)
(LSB) So, 0.2510 = 0.012
0.25 X 2 0.50 X 2 1.00
Therefore, Refer to conversion of binary to hexadecimal 21.2510 = 010 101 . 0102 = 25.28
From Base 10 to Base 16
Base 10 5,735 Remainder 5,735 ( 7 Least significant bit 358 ( 6 22 ( 6 1 ( 1 Most significant bit 0 Base 16 1667
Quotient
16 ) 16 ) 16 ) 16 )
From Base 10 to Base 16
Base 10
Quotient 16 ) 16 ) 16 ) 16 )
8,039 Remainder
8,039 ( 7 Least significant bit 502 ( 6 31 ( 15 1 ( 1 Most significant bit 0
Base 16
1F67
From Base 10 to Base 16
Convert 2110 to hexadecimal.
21 16 1 16 = = 1 balance 5 0 balance 1 (LSB) (MSB)
Therefore , 2110 = 1516
From Base 10 (decimal point) to Base 16
Convert 21.2510 to hexadecimal. 16 21 16 1 0 5 1 4 0.25 16 4.00
Therefore, 21.2510
15.416
From Base 10 (decimal point) to Base 16
Convert 21.2510 to hexadecimal. (OTHER METHOD)
21 2 = 10 10 2 = 5 52 = 2 22 = 1 12 = 0 So, 2110 = 101012
balance balance balance balance balance
1 0 1 0 1
(LSB)
Now, (MSB) 0 1
(MSB)
(LSB) So, 0.2510 = 0.012
0.25 X 2 0.50 X 2 1.00
Therefore, Refer to conversion of binary to hexadecimal 21.2510 = 10101 . 01002 = 15.416
EXERCISES
1. Find the binary representation for 31.62510. Show your work. 1. Convert the following numbers to the respective numbering system.
5610 base 8 (until 5 binary point)
2. Convert 95.2510 to hexadecimal.