中国高校课件下载中心 》 教学资源 》 大学文库

英格兰萨里大学:《C语言》课程教学资源(讲义)Lecture 2 - Binary Representation

文档信息
资源类别:文库
文档格式:PDF
文档页数:3
文件大小:83.95KB
团购合买:点击进入团购
内容简介
英格兰萨里大学:《C语言》课程教学资源(讲义)Lecture 2 - Binary Representation
刷新页面文档预览

rrodcsLecture2BinaryNumberSystemsih.Decimalisabase10numbersystem-1's,10's,100's,1000'setc.Binary is justa base2numbersystem- 1,2,4, 8, 16 etc·Abinaryvariable can have2states 1/0, on/off, +5v/Ov·Forexample,thebinaryequivalentofthedecimalnumber26is11010which is11010=1x24+1x23+0x22+1x21+0x20OtherNumberSystemsBinaryNumberSystemsHexadecimal and Octal Number SystemsbitBinary numbers are a convenient representation for manipulation byOnebinarydigit0or1digital computers,but not byhuman beings.Itis often advantageoustocovetabinarynumber intoitshexadedmal (base16)oroctabyte(base 8) representationers from 0-255caahlai.e.1001010tThefootablesnibbledecmal.binary,octal andA group of 4 bits, Le. 1001hexadecimaworcMost computer systems organise their memories in groups of bytesagbitwodeword consists of two bytes,a thirty-two-bit word consists of foubytes, and so on.LogicalOperationsonBinaryNumberSystemConversionNumberSystemsbyte th10000

1 1. Introduction 2. Binary Representation 3. HardwareandSoftware 4. HighLevel Languages 5. Standard inputand output 6. Operators, expression and statements 7. MakingDecisions 8. Looping 9. Arrays 10. Basics of pointers 11. Strings 12. Basics of functions 13. Moreabout functions 14. Files 14. DataStructures 16. Casestudy:lottery number generator Lecture 2 Binary Number Systems • Decimal is a base 10 number system – 1’s, 10’s, 100’s, 1000’s etc • Binary is just a base 2 number system – 1, 2, 4, 8, 16 etc • A binary variable can have 2 states – 1/0, on/off, +5v/0v • For example, the binary equivalent of the decimal number 26 is 11010, which is 11010 = 1x24 + 1x23 + 0x22 + 1x21 + 0x20 Binary Number Systems • bit – One binary digit 0 or 1. • byte – A group of 8 bits capable of representing binary numbers from 0-255 i.e. 10010101 • nibble – A group of 4 bits, i.e. 1001 • word – Most computer systems organise their memories in groups of bytes called words. An eight-bit word consists of one byte, a sixteen-bit word consists of two bytes, a thirty-two-bit word consists of four bytes, and so on. Other Number Systems • Hexadecimal and Octal Number Systems – Binary numbers are a convenient representation for manipulation by digital computers, but not by human beings. It is often advantageous to convert a binary number into its hexadecimal (base 16) or octal (base 8) representation. The following table shows the representation of numbers in decimal, binary, octal and hexadecimal. Decimal Binary Octal Hexadecimal 00 0000 00 0 01 0001 01 1 02 0010 02 2 03 0011 03 3 04 0100 04 4 05 0101 05 5 06 0110 06 6 07 0111 07 7 08 1000 10 8 09 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F Number System Conversion e.g. the decimal value 77 is represented as a binary byte thus 7710 = 0100 1101 and in hexadecimal and octal as 4D and 115 respectively 0100 1101 01 001 101 4 D 11 5 By knowing the binary code for hexadecimal and octal digits, the binary code for multi-byte numbers can be easily constructed. The binary representation of the four byte value #1EA7 (where # denotes hexadecimal) is 0001 1110 1010 0111 1EA7 Logical Operations on Binary Number Systems A B f 0 0 0 0 1 0 1 0 0 1 1 1 A B f 0 0 0 0 1 1 1 0 1 1 1 1 A f 0 1 1 0 A B f 0 0 0 0 1 1 1 0 1 1 1 0

AddingBinaryNumbersDear SirIamwritingwith10111011011eeards to.1001011010011S=AB+AB101011C=AB.Performs the function of a half adder adds 2 binaryA BSum Carrynumbers together:01004TFCharactersSound:Mostcommonstandardforrepresentingcharacters isASCll,7bit code27=128 American Standard Code for Information Interchangeeg.181878185226823LL11101011110010Tios1110010Waveforms can be digitised by sampling the waveform at..e1911100101regular intervals producing a binary,discrete representation1111001V460101110ofa continuous signalImagesandMoviesAlgorithms·An intensity image is represented as aprocess get_drunk:rectangular array of pixels,where each pixelrepeathasan intensityvalue.buy-lageropen-canrepeatlift-to-mouthswallowuntil can-is-emptyuntil no-money oR paralytic2

2 Adding Binary Numbers • Performs the function of a half adder – adds 2 binary numbers together C AB S AB AB = = + A B Sum Carry 000 0 011 0 101 0 110 1 Dear Sir I am writing with regards to. 10111011011 1001011010011 101011. How to we get from text, images, sound and movies to a language the computer can understand ? Characters • Most common standard for representing characters is ASCII, 7 bit code 27=128 – American Standard Code for Information Interchange eg. dec binary hex s 83 1010011 53 u 117 1110101 75 r 114 1110010 72 r 114 1110010 72 e 101 1100101 65 y 121 1111001 79 . 46 0101110 2E Sound • Waveforms can be digitised by sampling the waveform at regular intervals producing a binary, discrete representation of a continuous signal Images and Movies • An intensity image is represented as a rectangular array of pixels, where each pixel has an intensity value. Algorithms process get_drunk: repeat buy-lager open-can repeat lift-to-mouth swallow until can-is-empty until no-money OR paralytic

AlgorithmsAlgorithms·Each instruction in the instruction set.You are Address 0.can be represented by an arbitrary· Obey only instructions sent to Address 0binarycode.·Stayfacingtheaudience·Instruction set::2volunteers00Walk forward 2 step01Walkbackward 2 steps10Walk left2 steps11Walk right 2 stepsAlgorithmsAlgorithmsAddressInstruction.YouareAddress1000·ObeyonlyinstructionssenttoAddress1101swap places01AStayfacingtheaudience.000·Instruction set:A0100swap back00Walk forward 2 step11101Walkbackward 2 steps01110Walk left 2 steps11Walk right 2 stepsStudent O stage leftStudent 1 stage rightBOOKSAlgorithmsRecommended course book:Sams Teach Yourself C in 21 Days, by Peter Aitken and Bradey LJones,Sams Publishing目目Sams Teach Yourself C in 24 Hours(Znd edition),by Tony Zhang..--:::::::SamsPublishing----- C - A Reference Manual (4th edition), by Samuel Harbison and GuySteele, Prentice HallOther Books Structured Computer Organisation by Andrew S Tanenbaum,enticeHall C How to Program, by HarveyDeltel and Pau DellelPrenice HCProgram Design forEngineers, by Hanly.Kofman and HorvahAddison-Wesley- Beginners Guide to C, by ivar Horton, Wrox Press3

3 Algorithms • Each instruction in the instruction set can be represented by an arbitrary binary code. • 2 volunteers Algorithms • You are Address 0. • Obey only instructions sent to Address 0 • Stay facing the audience • Instruction set: 0 0 Walk forward 2 step 0 1 Walk backward 2 steps 1 0 Walk left 2 steps 1 1 Walk right 2 steps Algorithms • You are Address 1. • Obey only instructions sent to Address 1 • Stay facing the audience • Instruction set: 0 0 Walk forward 2 step 0 1 Walk backward 2 steps 1 0 Walk left 2 steps 1 1 Walk right 2 steps Algorithms Address Instruction 0 00 1 10 0 11 0 01 1 00 0 10 1 11 1 01 Student 0 stage left Student 1 stage right swap places swap back Algorithms ADD INST 0 01 1 11 0 00 1 11 1 10 1 01 0 01 1 11 0 11 0 00 0 00 1 01 0 10 0 11 1 01 1 01 1 11 0 10 1 01 0 11 0 00 1 11 1 11 0 01 1 01 0 01 ADD INST 0 01 1 11 0 00 1 11 1 10 1 01 0 01 1 11 0 11 0 00 0 00 1 01 0 10 0 11 1 01 1 01 1 11 0 10 1 01 0 11 0 00 1 11 1 11 0 01 1 01 0 01 ADD INST 0 01 1 11 0 00 1 11 1 10 1 01 0 01 1 11 0 11 0 00 0 00 1 01 0 10 0 11 1 01 1 01 1 11 0 10 1 01 0 11 0 00 1 11 1 11 0 01 1 01 0 01 ADD INST 0 01 1 11 0 00 1 11 1 10 1 01 0 01 1 11 0 11 0 00 0 00 1 01 0 10 0 11 1 01 1 01 1 11 0 10 1 01 0 11 0 00 1 11 1 11 0 01 1 01 0 01 ADD INST 0 01 1 11 0 00 1 11 1 10 1 01 0 01 1 11 0 11 0 00 0 00 1 01 0 10 0 11 1 01 1 01 1 11 0 10 1 01 0 11 0 00 1 11 1 11 0 01 1 01 0 01 ADD INST 0 01 1 11 0 00 1 11 1 10 1 01 0 01 1 11 0 11 0 00 0 00 1 01 0 10 0 11 1 01 1 01 1 11 0 10 1 01 0 11 0 00 1 11 1 11 0 01 1 01 0 01 ADD INST 0 01 1 11 0 00 1 11 1 10 1 01 0 01 1 11 0 11 0 00 0 00 1 01 0 10 0 11 1 01 1 01 1 11 0 10 1 01 0 11 0 00 1 11 1 11 0 01 1 01 0 01 ADD INST 0 01 1 11 0 00 1 11 1 10 1 01 0 01 1 11 0 11 0 00 0 00 1 01 0 10 0 11 1 01 1 01 1 11 0 10 1 01 0 11 0 00 1 11 1 11 0 01 1 01 0 01 ADD INST 0 01 1 11 0 00 1 11 1 10 1 01 0 01 1 11 0 11 0 00 0 00 1 01 0 10 0 11 1 01 1 01 1 11 0 10 1 01 0 11 0 00 1 11 1 11 0 01 1 01 0 01 BOOKS • Recommended course book: – Sams Teach Yourself C in 21 Days, by Peter Aitken and Bradley L. Jones, Sams Publishing – Sams Teach Yourself C in 24 Hours (2nd edition), by Tony Zhang, Sams Publishing – C - A Reference Manual (4th edition), by Samuel Harbison and Guy Steele, Prentice Hall • Other Books – Structured Computer Organisation by Andrew S Tanenbaum, Prentice Hall – C How to Program, by Harvey Deitel and Paul Deitel, Prentice Hall – C Programming Language (2nd Edition) by Brian Kernigham and Dennis Ritchie, Prentice Hall. – C Program Design for Engineers, by Hanly, Koffman and Horvath, Addison-Wesley – Beginners Guide to C, by Ivor Horton, VVrox Press

已到末页,全文结束
刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档