Presentation is loading. Please wait.

Presentation is loading. Please wait.

THE BINARY SYSTEM.

Similar presentations


Presentation on theme: "THE BINARY SYSTEM."— Presentation transcript:

1 THE BINARY SYSTEM

2 HOW A COMPUTER STORES DATA
A computer is an information-processing machine that works by converting all kinds of information into binary numbers (1s and 0s). A computer treats any type of information (numbers, letters, words, etc.) as if it consisted simply of binary ones and zeros. For example, a computer can translate the letter “A” typed into its keyboard into a string of 1s and 0s, such as One reason to do this is that once in binary form; the information can be stored and moved about more easily. For example, on a hard disc, the 1s could be stored as magnetized spots on the disc, while the 0s can be stored as unmagnetized spots. Once information has been converted to 1s and 0s, the computer can work on it.    All of a computer’s functions are based on the movement and transformation of electrical pulses (representing 1s and 0s) in electrical circuits. Inside the computer are electrical circuits that perform computations on the 0s and 1s, such as adding and subtracting them.

3 The Decimal/Denary Number System (Base 10)
The decimal number system that people use every day contains ten digits, 0 through 9. Start counting in decimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, Units/Ones 1 2 3 4 5 6 7 8 9 Oops! There are no more digits left. How do we continue counting with only ten digits?

4 The Decimal/Denary Number System
We add a second column of digits, worth ten times the value of the first column. Start counting again: 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 Tens Ones (Note that the right column goes back to zero here.), 21, 22, 23, ... , 94, 95, 96, 97, 98, 99,

5 The Decimal/Denary Number System
Oops! Once again, there are no more digits left. The only way to continue counting is to add yet another column worth ten times as much as the one before. Continue counting: 100, 101, 102, , 998, 999, 1000, 1001, 1002, .... H T O Th H T O You should get the picture at this point!

6 The Decimal/Denary Number System
Example, the decimal number 365 can be written in expanded notation as: H T O (3×100) + (6×10) + (5×1) Th H T O 1032= (1×1000) + (0×100) + (3×10) + (2×1). By writing numbers in this form, the value of each column becomes clear.

7 The Binary System/Base 2
The binary number system works in the exact same way as the decimal system, except that it contains only two digits, 0 and 1. Start counting in binary: 0, 1, Oops! There are no more binary digits. In order to keep counting, we need to add a second column worth twice the value of the column before. We continue counting again: 10, 11, Oops! It is time to add another column again. Counting further: 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, Watch the pattern of 1's and 0's. You will see that binary works the same way decimal does, but with fewer digits.

8 The Binary System/Base 2
Binary uses two digits, so each column is worth twice the one before. N.B. Any number to the power 0 is 1 A A1 A = 1 & A1 = A (1-1) = A 0 = 1

9 Decimal (Base 10) Binary (Base 2) 0 one 1 1 one 2 10 0 one, 1 two 3 11 1 one, 1 two 4 100 0 one, 0 two, 1 four 5 101 1 one, 0 two, 1 four 6 110 0 one, 1 two, 1 four 7 111 1 one, 1 two, 1 four 8 1000 0 one, 0 two, 0 four, 1 eight

10 Conversion of a binary number to a decimal number
To convert a number from binary to decimal, simply write it in expanded notation. For example, the binary number can be rewritten in expanded notation as (1×32) + (0×16) + (1×8) + (1×4) + (0×2) + (1×1)= = 45 By simplifying this expression, you can see that the binary number is equal to the decimal number 45.

11 Converting from decimal to binary
We use the method of repeated division by 2 to convert numbers from decimal to binary. Usually, when dividing a number by 2 the last binary digit (singles digit) must be a 1- the LSB. An even number will have a zero as the singles digit- the MSB. So to convert a Base 10 number to Base 2 the number is repeatedly divided by 2 until we have reached the point of 0 R 1. The remainders give us the binary digits.

12 Example: Convert decimal 25 to binary:-
25 ÷ 2 = 12 Remainder 1 12 ÷ 2 = 6 Remainder 0 6 ÷ 2 = 3 Remainder 0 3 ÷ 2 = 1 Remainder 1 1 ÷ 2 = 0 Remainder 1 The number 25 in decimal is equal to 110012 MSB LSB

13 QUESTIONS: Convert the following decimal numbers to binary. Use 8 bits to represent the numbers in base 2 16 182 97

14 BINARY ARITHMETIC OPERATIONS
Binary numbers can be added, subtracted, multiplied or divided just like decimal numbers. ADDITION RULES!! 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 1 0 = 1 1 Carry bits

15 BINARY ADDITION To view binary addition:

16 Note, the fourth rule in Binary Addition involves a ‘carry’ operation:
21 20 1 + 1 = 1 0 The place value is increased by 2! This is similar to decimal where the place value is increased by ten. For example: 9 + 1 =

17 Base 2 Addition questions
______ _____ _____

18 HOME-WORK Read pages 57-58: Log On to It for CSEC (2nd Ed.):-
Converting a decimal number to binary Adding binary numbers Do Exercise 1 Quest. 3, 4, 5 (Pg 59) Test Next Day!!!!!!!

19 REPRESENTATION SCHEMES
In computing, signed number representations are required to encode negative numbers in binary number systems. In maths, negative numbers in any base are represented by prefixing them with a − sign. However, in computer hardware, numbers are represented in binary only without extra symbols, requiring a method of encoding the sign of the number.

20 REPRESENTATION SCHEMES
Four methods that are used to represent signed numbers are: Sign-and-Magnitude One’s complement Two’s Complement Binary Coded Decimal (BCD)

21 SIGN AND MAGNITUDE The simplest way to indicate negation is signed magnitude .One may first approach the problem of representing a number's sign by allocating one sign bit to represent the sign: set that bit (often the most significant bit) to 0 for a positive number, and set to 1 for a negative number. The remaining bits in the number indicate the magnitude. Some early binary computers (e.g. IBM 7090) used this representation

22 SIGN AND MAGNITUDE Consider a number with n bits:
The left-most bit represents the sign of the number +/- sign. "0" indicates that the number is positive, "1" indicates negative. The remaining n-1 bits represent the magnitude (size) of the number.

23 Representation of positive and negative numbers using Sign & Magnitude
BINARY DECIMAL 0000 +0 0001 +1 0010 +2 0011 +3 0100 +4 0101 +5 0110 +6 0111 +7 1000 -0 1001 -1 1010 -2 1011 -3 1100 -4 1101 -5 1110 -6 1111 -7 What observations have you made from the table?

24 If you observed that there are two values for zero: +0 and -0 then you are RIGHT!

25 Example 1: Represent 45 in binary using Sign and Magnitude:
4510 = Therefore +45 (S & M) = 0 (MSB) = +ve in Sign and Magnitude

26 Example 2: Represent -45 in binary using Sign and Magnitude:
4510 = Therefore -45 (S & M) = 1 (MSB) = -ve in Sign and Magnitude

27 Example 3: Represent 1011 in decimal using Sign and Magnitude.
1 = -ve in Sign & Magnitude 011=(1x2) + (1x1) = 3 Therefore 1011 = -3 (using Sign & Magnitude) 22 21 20 4 2 1

28 Example 4: Represent 0011 in decimal using Sign and Magnitude.
0 = +ve in Sign & Magnitude 011=(1x2) + (1x1) = 3 Therefore 0011 = +3 (using Sign & Magnitude) 22 21 20 1

29 Questions 1. using Sign & Magnitude Representation, find the binary representation of the numbers: (a) 25 (b) -25 (c) (d) -120 2. What is the decimal equivalent of the following binary numbers (using S & M scheme)? (a) (b) (c)

30 HOME-WORK 1. Using Sign & Magnitude Representation, find the binary representation of the numbers: (a) 64 (b) -96 (c) 96 (d) What is the decimal equivalent of the following binary numbers (using S & M scheme)? (a) (b) (c) * Read Page 55 (blue book) or pg 60 (purple book)- One’s & Two’s Complement

31 One’s Complement In one's complement, positive numbers are represented as usual in regular binary. Example: 5 in binary is The One’s complement of 5 would be: However, negative numbers are represented differently. To negate a number, replace all zeros with ones, and ones with zeros - flip the bits. One consequence of this is that there are two values for zero: +0 and -0.

32 For example, for a four-bit number (remember, the leading -- that is, leftmost -- bit is a sign bit) using 1’s Complement: Binary: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Decimal:  +0 +1 +2 +3 +4 +5 +6 +7 -7 -6 -5 -4 -3 -2 -1 -0

33 Questions Represent the following numbers in binary (using 8 bits) using 1’s complement: -108 23 4 -120

34 HOME-WORK 1. Represent the following decimal numbers using 1’s complement: -95 -36 100 2. Find the One’s Complement of:

35 TWO’S COMPLEMENT Two's complement is the way every computer chooses to represent integers. Using two's complement as the method for representing negative numbers allows us to have only one representation of zero, and to have effective addition and subtraction while still having the most significant bit as the sign bit. The leading bit of a number is the sign bit.  Positive numbers have a zero as the leading bit; negative numbers have a one as the leading bit. There is only one value for zero: all bits are zero (as opposed to the system used for One's Complement Overflow can occur (if numbers are of the same sign)

36 For example, for a four-bit number (remember, the leading -- that is, leftmost -- bit is a sign bit) USING 2’S COMPLEMENT Binary: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Decimal:  +1 +2 +3 +4 +5 +6 +7 -8 -7 -6 -5 -4 -3 -2 -1

37 TWO’S COMPLEMENT In two's complement, positive numbers are represented as usual in regular binary. Example: 5 in binary is The Two’s complement of 5 would be: NO CHANGE!!

38 FINDING TWO’S COMPLEMENT (-VE NUMBERS)
Convert the number to binary Find one’s complement Add 1 to the 1’s complement

39 Example: Suppose we're working with 8 bits and we want to find how -28 would be expressed in two’s complement notation: STEP 1: First we write out 28 in binary form. 28 = STEP 2: Then we invert the digits. 0 becomes 1, 1 becomes 0. Therefore the 1’s Complement of: = STEP 3: Add 1 to the 1’s Complement: = Therefore, -28 =

40 QUESTIONS Represent the following numbers in binary (using 8 bits) in 2’s complement: -108 6 -123

41 QUESTIONS Find the two’s complement representation of the following using 8 bits: 1011 11001

42 HOME-WORK Represent the following numbers in binary (using 8 bits) in 2’s complement: -64 7 Find the two’s complement representation of the following using 8 bits: 101010 11101

43 HOME-WORK Cont’d Read Pg (Log On to IT for CSEC 2nd Ed.)- BCD and Data Representation. Review Sign and Magnitude, 1’s Complement and 2’s Complement and Addition for Test next day!

44 Adding a negative number- using Two’s complement
Example: Find the value of 9-6 using four-bit two’s complement binary. 9 – 6 could also be written as 9 + (-6)

45 1. Convert 9 to binary 9= 10012 2. Find the Two’s Complement of -6: 6= 0110 1’s Complement = 1001 Add 1 = = 1010 Therefore -6 (2’s Comp.) = 1010 3. Add 9 to -6 = = 10011 Discard the extra bit because we are using 4-bit representation. (using two’s compl.) = 00112

46 HOME-WORK Find the value of the following using eight-bit two’s complement: 15-8 50-25 -8+12 Read Pg (Log On to IT for CSEC, 2nd Ed.: BCD and ASCII

47 BINARY CODED DECIMAL- BCD
BCD is an encoding system for decimal numbers in which each digit is represented by its own binary sequence. In BCD, a digit is usually represented by four bits which, in general, represent the decimal digits 0 through 9. Other bit combinations are sometimes used for a sign.

48 BCD 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 + 1010 - 1011

49 Example 1: What is the BCD representation of -325? - = 1011 3 = 0011 2 = 0010 5 = 0101 Therefore 325 =

50 Example 2: What is the BCD representation of 325? + = 1010 3 = 0011 2 = 0010 5 = 0101 Therefore -325 =

51 Questions: What is the BCD representation of the following decimal numbers? 56 -63 -4 1005

52 DATA REPRESENTATION Two of the most common codes used to represent character sets in computers are: 1. ASCII (American Standard Code for Information Interchange). 2. EBCIDIC (Extended Binary Coded Decimal Interchange Code).

53 ASCII CODE A to Z a to z

54 Example 1: The ASCII code for the letter A is Determine the 7-bit ASCII code for the letter G. A = G is the 6th letter from A 6 = 110 Therefore: = *see text book for other methods

55 Questions 1. What letter is represented by the binary representation using ASCII? 2. The ASCII representation for the letter t is What is the ASCII representation of the letter y? 3. Determine the ASCII representation of : (i) G (ii) d (iii) R


Download ppt "THE BINARY SYSTEM."

Similar presentations


Ads by Google