Summary

This document introduces the concept of number systems, focusing on decimal, binary, and hexadecimal. It explains how to convert between these systems and details basic arithmetic operations. The document is likely part of a university programming class.

Full Transcript

Chapters 1&2 Big Picture, Binary Values and Number Systems Layers of a Computing System These layers establish the general organization of the course Do we need to know all these layers to be able to use computers? Does that overwhelming?...

Chapters 1&2 Big Picture, Binary Values and Number Systems Layers of a Computing System These layers establish the general organization of the course Do we need to know all these layers to be able to use computers? Does that overwhelming? 2 4 Abstraction Concept We don’t need to know how the engine works We need to know only some basics about how to interact with the car 3 Abstraction Concept Abstraction is a way to think about something, which hides complex details Abstraction leaves only the information necessary to accomplish our goal When we are dealing with a computer in one layer we don’t need to think about the details of the other layers 4 Computing Systems In this course, we explore – how computers work, – what they do – how they do it What is the difference between hardware and software? Hardware: refers to the physical elements of a computing system (printer, circuit boards, wires, keyboard…) Software: describes programs that provide the instructions (commands) for a computer to execute 5 Data and Computers In the past, computers deal almost exclusively with numeric and textual data Today computers are really multimedia devices: dealing with a vast array of information categories such as: o Numbers o Text o Audio o Video o Images and graphics 6 Decimal Versus Binary External representation is human oriented Internal representation is computer oriented 7 Numbers Integers Positive and negative numbers: 249, 0, - 45645, - 32 Rational Numbers A number that can be made by dividing two integers: – ½ or (0.5) is a rational number (1 divided by 2, or the ratio of 1 to 2) – 0.75 is a rational number (3/4) – −6.6 is a negative rational number (−66/10) 8 Number Systems 3 main issues are addressed: – Convert numbers in other bases to base 10 (decimal) – Convert base 10 numbers to numbers in other bases (2, 8, 16) – Describe the relationship between bases 2, 8, and 16 24 96 Positional Notation How many ones are there in 642? Aha! 642 is 600 + 40 + 2 in Base 10 (each digit has its own dedicated value!) The Base of a number determines both: The number of different digit symbols The values of digit positions 10 Positional Notation Positional notation of (642) in Base 10: 6 x 102 = 6 x 100 = 600 + 4 x 101 = 4 x 10 = 40 + 2 x 10º = 2 x 1 = 2 = 642 in base 10 The power indicates the position of This number is in the number base 10 11 6 Positional Notation What if 642 has the base of 13? 6 x 132 (6 x 169 = 1014) + 4 x 131 (4 x 13 = 52) + 2 x 13º (2 x 1 = 2) = 1068 in base 10 642 in base 13 is equivalent to 1068 in base 10 What if 642 has the base of 8 (Octal)? 12 Binary System Decimal is base 10 and has 10 digit symbols: 0,1,2,3,4,5,6,7,8,9 Binary is base 2 and has 2 digit symbols: 0,1 Using binary system instead of the decimal system simplifies the design of computers and related technologies All data stored inside a computer is stored in binary (also called machine language) and interpreted to display on the screen in human language 13 Bases Higher Than 10 How are digits in bases higher than 10 represented? Base 16 (Hexadecimal) has 16 digits: 0,1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F 14 10 Converting Other Bases to Decimal What is the Decimal equivalent of the Octal number 642? 6 x 82 (6 x 64 = 384) + 4 x 81 (4 x 8 = 32) + 2 x 8º (2 x 1 = 2) = 418 in base 10 15 Converting Hexadecimal to Decimal What is the Decimal equivalent of the Hexadecimal number DEF? D x 162 (13 x 256 = 3328) + E x 161 (14 x 16 = 224) + F x 16º (15 x 1 = 15) = 3567 in base 10 Remember, the digit symbols in base 16 are: 0,1,2,3,4,5,6,7,8,9,A,B,C, D,E,F | ….. | | | | | | 0, …. 10,11,12,13,14,15 16 Converting Decimal to Other Bases An algorithm is a logical sequence of steps that solve a problem or the plan for a solution (we have much more to say) Algorithm for converting a number in base 10 to other bases: – While (the quotient is not zero) 1) Divide the decimal number by the new base 2) Make the remainder the next digit to the left in the answer 3) Replace the original decimal number with the quotient 17 Converting Decimal to Binary What is 13 (in base 10) in base 2? 13 ÷ 2 quotient = 6 remainder 1 order for 6÷2 quotient = 3 remainder 0 reading the 3÷2 quotient = 1 remainder 1 remainder digits 1÷2 quotient = 0 remainder 1 Stop, because the quotient is now zero Answer: 1 1 0 1 18 Converting Decimal to Octal What is 93 (in base 10) in base 8? 93 ÷ 8 quotient 11 remainder 5 order for 11 ÷ 8 quotient 1 remainder 3 reading the remainder 1 ÷ 8 quotient 0 remainder 1 digits Answer: 1 3 5 19 Converting Decimal to Hexadecimal What is 93 (in base 10) in base 16? order for 93 ÷ 16 quotient 5, remainder 13 reading the 5 ÷ 16 quotient 0, remainder 5 remainder digits Answer: 5D Hint: 13 in base 16 is replaced by D 20 Converting Binary to Octal When it comes to conversion from Binary to Octal two steps are necessary: Octal 0 1 2 3 4 5 6 7 Binary 000 001 010 011 100 101 110 111 1) Mark groups of three (from right) 2) Convert each group and replace it with a corresponding Octal number 10101011 10 101 011 2 5 3 10101011 in base 2 is 253 in base 8 21 17 Converting Binary to Hexadecimal Another straightforward relationship: Hex Binary 0 0 0 0 0 1 0 0 0 1 1) Mark groups of four (from right) 2 0 0 1 0 2) Convert each group and replace 3 0 0 1 1 4 0 1 0 0 it with a corresponding 5 0 1 0 1 Hexadecimal number 6 0 1 1 0 7 0 1 1 1 8 1 0 0 0 9 1 0 0 1 A 1 0 1 0 10101011 1010 1011 B 1 0 1 1 C 1 1 0 0 A B D 1 1 0 1 10101011 in base 2 is AB in base E 1 1 1 0 F 1 1 1 1 16 22 18 More Examples- Converting Binary to Decimal What is the Decimal equivalent of the Binary number 1101110? Formal approach: 1 x 26 (1 x 64 = 64) + 1 x 25 (1 x 32 = 32) + 0 x 24 (0 x 16 = 0) + 1 x 23 (1 x 8 = 8) + 1 x 22 (1 x 4 = 4) + 1 x 21 (1 x 2 = 2) + 0 x 2º (0 x 1 = 0) = 110 in base 10 Intuitive approach: Value of the first digit is 2º, value of the second digit is 21 and so on 23 13 A Typical Base Calculator Try some! Converting different base numbers to each other: http://www.cleavebooks.co.uk/scol/calnumba.htm 24 Converting Decimal to Binary What is 893 in base 2 (take intuitive approach)? Powers of 2 512 256 128 64 32 16 8 4 2 1 Quotient Q 1 1 0 1 1 1 1 1 0 1 Remainder R 381 125 61 29 13 5 1 0 893 is 1101111101 in base 2 25 19 Converting Decimal to Hexadecimal What is 956 (in base 10) in base 16? 956 ÷ 16 quotient 59, remainder 12 59 ÷ 16 quotient 3, remainder 11 3 ÷ 16 quotient 0, remainder 3 Answer: 3BC Practice: What is 3BC (in base 16) in base 2? Practice: What is 760 (in base 8) in base 2? 26 20 Converting Decimal to Hexadecimal (Lab1 Demo) 27 Adding and Subtracting Binary Numbers It is possible to add and subtract binary numbers in a similar way to base 10 numbers o E.g. 1 + 1 = 2 in base 10 becomes 1 + 1 = 10 in binary (that is, 0 with a carry of 1) o In the same way, 2 - 1 = 1 in base 10 becomes 10 – 1 = 1 in binary When you add and subtract binary numbers you will need to be careful when there is carrying or borrowing as these will take place more often 28 Adding Binary Numbers Remember that there are only 2 digit symbols in binary, 0 and 1 Key addition results for binary numbers: 0+0=0 1+0=1 1 + 1 = 10 (1 is carry and 0 is sum) 1 + 1 + 1 = 11 (1 is carry and 1 is sum) 29 Addition in Binary 1 + 1 is 0 with a carry of 1 Carry Values 1011111 1010111 +1 0 0 1 0 1 1 10100010 Resource: http://courses.cs.vt.edu/~csonline/NumberSystems/Lessons/Additio n/index.html 30 14 Binary Addition Practice Do Practice: perform the following binary additions: a) 1101011 b) 101001 + 1111011 + 011111 ______ ______ 11100110 1001000 31 Subtraction in Decimal Reminder: perform the following decimal subtractions: 271- 201- 89 89 ------- ------- 182 112 32 Subtraction in Binary Key subtraction results for binary numbers: 1–0=1 0 10 – 1 = 1 -1 11 – 1 = 10 ------- 11 (1 borrow and 1 subtraction) 33 Subtraction in Binary Resources: http://courses.cs.vt.edu/~csonline/NumberSystems/Lessons/Subtracti on/index.html http://sandbox.mc.edu/~bennet/cs110/pm/sub.html?utm_campaign=Do nanimHaber&utm_medium=referral&utm_source=DonanimHaber 34 Binary Subtraction Practice Do Practice: perform the following binary subtractions: 1100 11010 - 0111 - 01001 ______ ______ 0101 10001 35 Binary Numbers and Computers Computers have storage units called binary digits or bits These storage units can store 2 different values (corresponding to 2 electric voltages) Low Voltage (off) = 0 High Voltage (on) = 1 All bits have 0 or 1 value Byte Definition: a group of 8 bits 36 Counting in Power-of-2 Bases 37 Octal and Hexadecimal Additions Do Practice: perform the following additions: (a) in Base 8 (b) in Base 16 157 F92B + 645 + 45A6 ____ ______ 1024 13ED1 38 Octal and Hexadecimal Additions Do Practice: perform the following additions: (a) in Base 8 (b) in Base 16 4712 9640 + 1234 + FECD _____ ______ 6146 1950D 39

Use Quizgecko on...
Browser
Browser