CS代考 UTF-32, UTF-16, UTF-8, and UTF-7. The numbers indicate the number of bits i

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 1007ICT / 1807ICT / 7611ICT Computer Systems & Networks 2B. Data Representation Last Lecture  Computerdata  Representingbinaryintegers  Convertingfrombinarytodecimal  Powersindifferentbases  Integerwordsizes  Convertingfromdecimaltobinary  Hexadecimalandoctalrepresentations © . Revised and updated by , , and Wee Lum 2 This Lecture's Content  Learningobjectives  Binaryaddition  Representingnegativenumbers  One’scomplementandTwo’scomplement  Representingcharacterdata,images,andaudio © . Revised and updated by , , and Wee Lum 3 Learning Objectives At the end of this lecture you will have:  Learnt how to perform binary addition  Learnt how to represent negative numbers in binary  Learnt how to apply One’s complement and Two’s complement Gained an understanding of how character data, images, and audio are represented digitally © . Revised and updated by , , and Wee Lum 4 Binary Addition  How do we add up binary numbers?  We add up each binary place and take any carry over into the next column.  EG: Single Bit Addition 0011A 0 1 0 1B+ 0 1 1 10  EG: Multiple Bit Addition 0111 0011 1100 0111 1001 A 0110 B+ 0010 0100 0110 10011 1010 1111 © . Revised and updated by , , and Wee Lum 5 Negative Integers (Section 4.2)  Sofarwehaveonlydealtwithpositiveintegers.  Weneedsomewayofrepresentingthesigns(+or-).  Wecouldtrymakingthemostsignificantbitinaword 0 for positive numbers and 1 for negative numbers. Sign 0 = +ve 1= -ve +2 = 0 0000010 -2 = 1 0000010 +127 = 0 1111111 -127 = 1 1111111 © . Revised and updated by , , and Wee Lum 6 Negative Integers Sign 0 = +ve 1= -ve © . Revised and updated by , , and Wee Lum 7 Negative Integers A problem with this approach, there are two zeroes: +0 = 0 0000000 -0 = 1 0000000 Sign 0 = +ve 1= -ve © . Revised and updated by , , and Wee Lum 8 Negative Integers B – C is equivalent to B + (-C)  Let’strytoadd+7to–5withbinaryadditionandusing the most significant bit as the sign bit  Thisdoesnotwork.Weneedsomeotherwayof representing negative numbers so addition works +7 0 0000111 -5 1 0000101 +2 1 0001100 = -12! © . Revised and updated by , , and Wee Lum 9 Sign 0 = +ve 1= -ve One’s Complement  Usingasignbitplusbinarymagnitudedoesnotwork.  Let’stryusingasignbitplusthebitwisecomplementof the magnitude.  Thecomplementofabinaryvalueisdefinedasfollows: Complement  Wecancomplementabinarynumberby complementing each of its bits (change all the 1s to 0s and all the 0s to 1s) Eg: Binary value: 1000111 Complement: 0111000 © . Revised and updated by , , and Wee Lum 10 One’s Complement  Usingasignbitplusbinarymagnitudedoesnotwork.  Let’stryusingasignbitplusthebitwisecomplement of the magnitude. +2 = 0 0000010 -2 = 1 1111101 +127 = 0 1111111 -127 = 1 0000000 +0 = 0 0000000 -0 = 1 1111111  Nowlet’strytoaddsomenumberslikebefore -4 1 1111011 +6 0 0000110 +2 (1)0 0000001 = +1! -3 1 1111100 -2 1 1111101 -5 (1)1 1111001 = -6! Carry Bit (ignored)  Stillwrongbutcloser–weareonlyoutby1.  Thecluetowhatiswrongisduetohaving2zeros © . Revised and updated by , , and Wee Lum 11 Two’s Complement (Approach 1)  Letstryone’scomplement+1fornegativenumbers (this is called Two’s complement)  +6=00000110 +2=00000010 -2=11111110  +5=00000101 +1=00000001 -3=11111101  +4=00000100 0=00000000 -4=11111100  +3=00000011 -1=11111111 -5=11111011  Nowletstrytoaddsomenumberslikebefore +7 0 0000111 -5 1 1111011 +2 (1)0 0000010 = +2 -3 1 1111101 -2 1 1111110 -5 (1)1 1111011 = -5 +3 0 0000011 -5 1 1111011 -2 (1)1 1111110 = -2 This works! © . Revised and updated by , , and Wee Lum 12 Two’s Complement (Approach 2)  Thereisanalternative(simpler)methodtoobtainthe Two’s complement for a number  Theapproachisasfollows: 1. Start from the right hand side of the binary number 2. For all bits to the left of the first 1 2.1. Change all 1s to 0s and all 0s to 1s First 1 from the right hand-side Values in red have been changed in Step 2.1. © . Revised and updated by , , and Wee Lum 13 Number Representations  Numbersarestoredasawordsizedsetofbits.  Itispossibletousebothsmallerandlargerwords sizes to represent numbers of different ranges.  Someprogramminglanguages(likeC)mightusethe following unsigned and signed data types on a 32 bit word size architecture: unsigned char unsigned int 0 .. 65535 unsigned long int 0 .. 4,294,967,296 -128.. +127 -32768 ..+32767 -2147483648 .. +2147483647 © . Revised and updated by , , and Wee Lum 14 I/O Data Types and Encoding  I/O devices need to represent a wide range of different data types  Keyboard presses  On screen text display  Bitmapped Images and Graphics  Audio, Video  A processor needs to be able to process all of these different types  Hence each of these data types has its own internal binary representation © . Revised and updated by , , and Wee Lum 15 Character Data (Section 4.4)  Keyboard input consists of a series of individual characters  Onscreen text display also consists of characters Each character is represented using an 8 bit code that is defined by the ASCII standard We can represent a string of characters using a string of hexadecimal words:“1007GC” = 31 30 30 37 47 43 © . Revised and updated by , , and Wee Lum 16 ASCII Table 'A' = 0x41 © . Revised and updated by , , and Wee Lum 17 Character Data  Thereareotherstandardsforrepresentingcharacters.  EBCDIC  The EBCDIC (Extended Binary Coded Decimal Interchange Code) is another 8 bit format introduced by IBM.  Unicode uses different sized codewords to represent many 1000’s of different characters to support a wide number of foreign languages.  The first 128 characters in Unicode are identical to ASCII.  There are several mapping (char to number) methods specified in Unicode: UTF-32, UTF-16, UTF-8, and UTF-7. The numbers indicate the number of bits in one codeword. In some cases a variable number of codewords can be used to represent each character.  Unicode is used in operating systems such as Windows 2000/XP, and in some compilers such as Java (a char in Java is 16 bits). © . Revised and updated by , , and Wee Lum 18 Bitmap Images A bitmap image is just a 2D array of unsigned numbers where each element specifies the colour at that location. The number of bits used to represent each pixel defines the number of colour shades that the bitmap can contain  Each individual element in the array is called a  A computer display is basically just a large bitmap 1 bit Image 12 x 10 pixels 4 bit Image 12 x 10 pixels 12 bits wide 48 bits wide © . Revised and updated by , , and Wee Lum Tan 0 = black 1 = white 0 = black F = white Colour Formats Colour bitmaps can be represented in various ways depending on the colour resolution of the output device The bit depth (N) determines the number of colours that can be simultaneously displayed on the screen = 2N  Bitmaps – use a single bit to represent each pixel (ON / OFF). GreyScale – uses up to 8 bits/pixel to generate output from black (0) to white (255). Colour mapped – uses 8 bits for each pixel as an index into a 24-bit colour (RGB) lookup table to display up to 256 colours (restricted version of True Colour) True Colour – uses 24-bits / pixel to represent the 3 primary colour components (R,G,B) using 8 bits each. May use 5 bits per component (15/16 bit colour).  Black(0,0,0), White (255,255,255), Red(255,0,0), Blue(0,0,255) etc  Some formats may use BGR instead of RGB  Some formats use 32bits to support an additional alpha channel that specifies transparency for each pixel as well as the RGB colour. © . Revised and updated by , , and Wee Lum 20 Audio and Sounds Waveform Audio file format is simply a digitised audio sound wave. Analogue audio is captured using a microphone and converted to digital in the sound card and stored as PCM. Analogue to Digital conversion first takes discrete samples or snapshots of the value of the sound wave in time and then quantises (or converts) the value of each sample into an unsigned number using a determined wordsize. The resulting representation is an array of unsigned words and is called Pulse Code Modulation (PCM)  8-bitExample:8060404020202040406080A0C0COE0E0E0 E0 Sound wave 60 sampled 40 © . Revised and updated by , , and Wee Lum 21 Have considered:  Binary number operations  One’s complement and two’s complement  Representing characters, images and audio © . Revised and updated by , , and Wee Lum 22  Digital Logic © . Revised and updated by , , and Wee Lum 23 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com