Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CS 106 Computing Fundamentals II Chapter 9 “Binary and Decimal” Herbert G. Mayer, PSU CS status 6/17/2013.

Similar presentations


Presentation on theme: "1 CS 106 Computing Fundamentals II Chapter 9 “Binary and Decimal” Herbert G. Mayer, PSU CS status 6/17/2013."— Presentation transcript:

1 1 CS 106 Computing Fundamentals II Chapter 9 “Binary and Decimal” Herbert G. Mayer, PSU CS status 6/17/2013

2 2 Syllabus George Boole George Boole Augustus De Morgan Augustus De Morgan Boolean Values Boolean Values 16 Boolean Operators 16 Boolean Operators Boolean And, Or, Xor, Not Boolean And, Or, Xor, Not De Morgan’s Theorem De Morgan’s Theorem Useful Urls Useful Urls Decimal Number System Decimal Number System Binary Number System Binary Number System

3 3 George Boole George Boole, 1815 to 1864, was a British mathematician, who developed Boolean Algebra (BA). He led a relatively uneventful life, being a private teacher at a young age in Doncaster, England, then math teacher in Liverpool, and in 1849 received an appointment as the first professor of mathematics at Queen's College, Cork Ireland. George Boole, 1815 to 1864, was a British mathematician, who developed Boolean Algebra (BA). He led a relatively uneventful life, being a private teacher at a young age in Doncaster, England, then math teacher in Liverpool, and in 1849 received an appointment as the first professor of mathematics at Queen's College, Cork Ireland. He published numerous unexciting paper in the world of mathematicians at the time. Of these, several are now regarded sine-qua-non standard material in Boolean Algebra, starting with his earliest publication on Theory of Analytical Transformations. Interestingly, the effective founder of the theory of computer science did not regard his specialty, BA, to be a branch of mathematics. His work influenced another contemporary founder of BA, Augustus De Morgan, living also in England from 1806 to 1871.

4 4 Augustus De Morgan Augustus De Morgan was born in 1806 in Mandura, India. Lived in England, graduated from Trinity College, Cambridge in 1827, with well-rounded, classical education. Became professor of mathematics at University College in London. De Morgan was renowned for his methods of making math interesting and stimulating to students. Died 1871 in London after producing a vast body of publications. Augustus De Morgan was born in 1806 in Mandura, India. Lived in England, graduated from Trinity College, Cambridge in 1827, with well-rounded, classical education. Became professor of mathematics at University College in London. De Morgan was renowned for his methods of making math interesting and stimulating to students. Died 1871 in London after producing a vast body of publications. Well known as Boole’s contemporary and articulator of De Morgan’s theorem; but it had been known already in the times of Aristotle.

5 5 Boolean Values The value domain of Boolean Algebra (BA) is limited to the two values True and False, in the computer science world also known as 0 and 1, represented via a bit. In the computer technology such a bit is represented by defined voltage values. For example, a value close to 0 V stands for False (or 0), while an electrical value of 1.1 V stands for True (or 1). The real value of using bits comes in their combination to large sequences of bit strings. Boolean functions (operators) are logic operation on bits. There are 16 distinct operations, including the trivial identities of always true or always false; all 16 are shown below:

6 6 16 Boolean Operators

7 7 Boolean And Boolean function a and b: true if and only if a and b are both true:

8 8 Boolean Or --Inclusive Boolean function a inclusive or b: true if a or b or both are true:

9 9 Boolean Or --Exclusive Boolean function a exclusive or b: true if value of a differs from b:

10 10 Boolean Not Boolean function not a: is true only if a is false:

11 11 De Morgan’s Theorem Assuming a and b are Boolean variables... and ^ is the logical-and, and v is the logical-or op Finally ! stands for the logical-not. Then: 1.) ! ( a ^ b ) = ( ! a ) v ( ! b ) 1.) ! ( a ^ b ) = ( ! a ) v ( ! b ) 2.) ! ( a v b ) = (! a ) ^ ( ! b ) 2.) ! ( a v b ) = (! a ) ^ ( ! b ) 1.) if the combined a and b condition is false, then at least one of a and b must be false 2.) if the combined a or b condition is false, then both a and also b must be false

12 12 Useful URLs

13 13 Decimal Numbers The decimal number system of our daily life uses 10 as the base to construct arbitrarily large values. Important in this system are the use of the value 0, and use of a series of powers of 10 increasing from right to left. Each digit position moving toward the left increases the exponent (of the power of 10). Why we use 10 as the base is not totally obvious, yet our having 10 fingers and 10 toes may have something to do with it. This decimal system had been used in the Arab civilization since times before Christ. Due to its superb qualities, the decimal number system has replaced the Roman number system in the western world. The Roman system was vaguely based on 10, but lacked the notion of a zero and the power series. In other ancient civilizations (Babylonian) 60 was a common numeric base, and today’s system of tracking time with 60 seconds per minute and 60 minutes per hour still is reminiscent of that practice. Other ancient cultures used 64 as the base, yet computers today use 2 as their base. Earlier computers with base 10 were also fairly common.

14 14 Decimal Numbers Decimal number 00001230 has the value one thousand, two hundred, and thirty. 00,001,230 similarly, except commas are added for better readability. Leading zeros have no value and can be ignored. Thus it is efficient to skip them. Trailing zeros after other decimal digits –before the implied decimal point— have enormous meaning, as they shift the complete range of all preceding digits to higher values. Decimal integers are generally written without decimal point. The actual, numeric value of decimal integers is constructed from right to left, with increasing exponent to the base 10: 0001230 = 0 * 10 0 + 3 * 10 1 + 2 * 10 2 + 1 * 10 3 + 0 * 10 4 + 0 * 10 5 + 0 * 10 6 For general decimal numbers the computation of the fractional value progresses left to right, with decreasing exponents for the base 10, starting with -1 (i.e. 10 -1 ) in the first position after the decimal point: 12.345 =(integral) 2 * 10 0 + 1 * 10 1 (fraction) 3 * 10 -1 + 4 * 10 -2 + 5 * 10 -3

15 15 Binary Numbers Binary number 0101 has value one hundred and one in binary or 5 in decimal. Like decimal numbers, leading zeros in the binary system have no value and can be ignored. However, since computers use a fixed number of bits for binary numbers, such unused bits are internally actually set to 0. Trailing zeros –before the implied binary point— have enormous meaning, as they shift the complete range of all preceding binary digits (bits). Binary integers are generally written without binary point. The actual, numeric integer value of binary integers is constructed from right to left, with increasing exponent to the base 2 from right to left: 0101 = 1 * 2 0 + 0 * 2 1 + 1 * 2 2 + 0 * 2 3 = 1 + 0 + 4 + 0 0101 = 1 + 0 + 4 + 0 0101 2 = 5 10 = 5 – decimal 5 is unambiguous, as no binary digit 5 exists!

16 16 Binary Numbers By convention, numbers (decimal or binary) are written without their base when the context is clear. But if the base is critical to know, a subscripted base is added for clarity. When the digit allows us to infer the base, then again it would be superfluous to spell out the base. For general binary numbers the computation of the fractional value progresses left to right, with decreasing exponents of base 2, starting with -1 for 2 -1 in the first position after the binary point: 101.11 = (integral) 1 * 2 0 + 0 * 2 1 + 1 * 2 2 + (fractional) 1 * 2 -1 + 1 * 2 -2 101.11 = (integral) 1 + 0 + 4 + (fractional) ½ + ¼ 101.11 2 = 5.75 10 = 5.75 -– 5.75 unambiguous, no binary digits 5 or 7 exist!

17 17 Binary Numbers

18 18 Binary Numbers Possible representations of binary numbers: sign- magnitude, one’s complement, and two’s complement representation (tcr). Advantage of tcr: computer needs no subtract unit, an adder suffices. When subtraction is needed, just add a negative number. Also there is no need for signed- and unsigned arithmetic; unsigned suffices. C++ uses heavily unsigned integers. In fact tcr HW implementations can ignore the sign bit. Just need an adder and inverter. Binary numbers in tcr use a sign bit and a fixed number of bits for the magnitude. For example, on a PC you may have 32-bit integers, one for the sign, 31 for the magnitude. When processed in a tcr architecture, the most significant bit is the sign bit, the other 31 bits hold the actual value of interest. By convention, sign bit value of 0 stands for positive and 1 for negative numbers.

19 19 Two’s Complement Representation To create a negative number in tcr, start out with the binary representation for the positive one, invert all bits, and add 1. Note that overflow cannot happen by inversion alone: the inverse (negative value) of all representable positive numbers can always be created. Overflow can happen during addition. Overflow occurs, when the sign bit’s carry-in is different from the sign bit’s carry-out, i.e. when the carry into the sign bit is different from the carry out of the sign bit. The number of negative numbers is one more than the number of positive ones (not counting 0). Naturally, there is also a 0, but no negative 0 in tcr, as we find in one’s complement (ocr) and sign- magnitude (smr) representations. To generate the absolute value of a negative number, invert all bits of the original negative number and add 1. It is important to add a 1 again, not to subtract it. However, there will be one negative value, whose positive inverse cannot be represented, causing overflow. That value is the smallest negative number. An 8-bit, signed tcr integer can hold integral values in the range from -128.. 127. See the asymmetry? See the one negative value that cannot be inverted?

20 20 Decimal to Binary Conversion Take the decimal number d to be converted to binary representation, and as long as d is not yet zero, do the following repeatedly: divide d by 2; the new value is d/2 / is integer divide, different from floating-point divide! note the remainder, it will be 0 or 1; call this the initial string s do repeatedly, until d is 0, each time adding one more remainder digit to s When done, read the digits of s backwards: that is number b in binary


Download ppt "1 CS 106 Computing Fundamentals II Chapter 9 “Binary and Decimal” Herbert G. Mayer, PSU CS status 6/17/2013."

Similar presentations


Ads by Google