1007ICT / 1807ICT / 7611ICT Computer Systems & Networks
2A. Data Representation
Last Lecture
Copyright By PowCoder代写 加微信 powcoder
Topics covered:
• Basic Components of Computer Systems
• Evolution of Computer Hardware
© . Revised and updated by , , and Wee Lum 2
This Lecture’s Content
Learningobjectives
Computerdata
Representingbinaryintegers
Convertingfrombinarytodecimal
Powersindifferentbases
Integerwordsizes
Convertingfromdecimaltobinary
Hexadecimalandoctalrepresentations
© . Revised and updated by , , and Wee Lum 3
Learning Objectives
At the end of this lecture you will have:
Gained an understanding of the nature of computer data
Learnt how to represent binary integers
Learnt how to convert from binary to decimal
Learnt how to represent powers in different bases
Gained an understanding of Integer word sizes
Learnt how to convert from decimal to binary
Gained an understanding of Hexadecimal and octal number representations
© . Revised and updated by , , and Wee Lum 4
Computer Data
(Section 1.5)
Note: Data is plural, datum is singular
Dataisbasicallyanytypeofinformationthatcanbe stored in a computer memory and processed.
Allkindsofinformationcanbestoredaslongasitcan somehow be represented using 1’s and 0’s (bits).
Someexamplesofdifferentdatatypes
Texts / characters
Differenttypesofnumbers
DataProcessingInstructions AudioandImagesetc
01000001 = letter “A” 00000011=Number3 00011001=Instruction“Add” 11111111=WhitePixel
Sinceeachoftheseisstoredasbits,howthosebitsare determined depends on what type of data the computer expects or thinks they are.
© . Revised and updated by , , and Wee Lum 5
Integer Representation (Section 1.6)
Anintegerisawholenumber(notarealnumber)
Integerscanberepresentedinbinaryformbywritingit in base 2 instead of our common base 10 notation.
In base 10 you count digits 0..9, then powers of 10, eg 10, 100
In base 2 you count digits 0..1, then powers of 2, eg 10(=2), 100(=4)
Anynumbercanbeevaluatedusingthisformula n
1x 100= 100
+ 2 x 10 = 20
d subscript i is the i-th digit
b superscript i is the base (or radix) raised to the i-th power
andthenumberisthesumoftermsfromi=0toi=n
and n is the number of digits in the number -1
© . Revised and updated by , , and Wee Lum 6
Binary Integers
Theplaceofadigitinabinarynumbergivesthe power of 2 that the value of the digit represents
Thevalueofabinarynumbercanbereadasfollows Bit Position 7
Number=1*27 +1*26 +0*25 +0*24 +0*23 +1*22 +0*21 +1*20 =1*128+1*64 +0*32+0*16+0*8 +1*4 +0*2 +1*1
Examples:BinarytoDecimalConversion 000000112 =2+1=3
000100102 =16+2=18
100001012 =128+4+1=133
111100002 =128+64+32+16=240
© . Revised and updated by , , and Wee Lum 7
Powers in Different Bases
Decimal Binary Hex / Octal Place
10,000,000
100,000,000
1,000,000,000
10,000,000,000
© . Revised and updated by , , and Wee Lum 8
Bits and Values
IfwehaveNbits,wecanrepresent2Ndifferent
values with those N bits.
No. Values
0 .. 65,535
4,294,967,296
0.. 4,294,967,295
0 .. 2N – 1
© . Revised and updated by , , and Wee Lum 9
Decimal to Binary Conversion (Section 1.6)
To convert any number N, base 10, to binary:
1. Find the largest power of 2 <= N, say 2X , then subtract 2X from N.
2. Substitute N- 2X for N, then repeat step 1 until (N- 2X) becomes 0.
3. Assemble the binary number with 1s in the bit positions corresponding to powers of 2 used in the decomposition of N, and 0s elsewhere.
Example Convert 770 to binary :
Step 1a) The largest power of 2 <= 770, is 29 or 512.
Step 1b) Subtract 512 from 770 which gives you 258.
Step 2a) The largest power of 2 <= 258, is 28 or 256.
Step 2b) Subtract 256 from 258 which gives you 2.
Step 3a) The largest power of 2 <= 2, is 21 or 2.
Step 3b) Subtract 2 from 2 which gives you 0. Stop finding powers of 2.
Step 4a) Powers of 2 used to decompose 770 are: 9, 8, and 1.
Step 4b) Set those bit positions to 1
© . Revised and updated by , , and Wee Lum 10
Alternate Decimal to Binary
Recursively divide the decimal number by 2, noting the remainder each time (which will be either 0 or 1).
When you hit 0, write the remainders in reverse for the answer Convert 71010 to binary:
Putting the remainders together (in reverse order) gives:
355 / 2 = 177 / 2 = 88/2= 44/2= 22/2= 11/2=
177, 88, 44, 22, 11,
Rotate Column
710 / 2 = 355,
remainder 0 remainder 1 remainder 1 remainder 0 remainder 0 remainder 0 remainder 1 remainder 1 remainder 0 remainder 1
71010 = 10110001102
© . Revised and updated by , , and Wee Lum Tan
5/2= 2/2= 1, 1/2= 0,
Hexadecimal (Section 2.6)
Hexadecimalandbinarynumbersarecloselyrelated since (16 is a power of 2. ie, 24 ), conversion between hexadecimal and binary is also straightforward.
Hexadecimalhas16digits(from0toF,or0tof):
SinceeachHexdigitonlyrequires4bitstorepresentit is easy to convert between binary and hexadecimal by grouping lots of four binary digits together.
Hexnumbersoftenhavea“0x”infronttoidentifythem
Hexnumberscanusecapitalsorlowercaseforletters
© . Revised and updated by , , and Wee Lum 12
Octal numbers are similar to hexadecimal but only has 8 digits (from 0 to 7)
Octal digits are made up from groups of 3 bits
© . Revised and updated by , , and Wee Lum 13
Have considered:
Representing binary integers
Conversion from binary to decimal
Hexadecimal and octal representations
© . Revised and updated by , , and Wee Lum 14
Binary addition
Representing negative numbers
One’s complement and Two’s complement
Representing character data, images, and audio
© . Revised and updated by , , and Wee Lum 15
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com