Sunteți pe pagina 1din 32

Green marble Binary For CXC S.

Edwards

Green marble What is binary? .Binary is simply a number system based on two, that is a number system that has only two digits and both being less than two. The Binary in computing is the same Binary in mathematics; it s just that it actually has an applied use. .Every day we count in or use a number system based on ten, this is called decimal. Computers also count in and use a number system, but they usually use one based on two not ten, in other words binary. .In decimal (base 10) there are ten digits from 0 to 9, and these are combined to form many numbers. In binary (base 2) there are two numbers, 0 and 1, and they are combined to form many numbers.

Green marble What is binary? .Every binary number has a decimal equivalent, and vice versa. .Examples of binary and decimal: 02= 010 12= 110 102= 210 112= 310 .As you can see the base or number system being used, is written subscript (just below) the number.

Green marble What is a Bit, Byte & Word? .A bitis simply a Binary Digit, a single unit of a binary number. .A byteis a collection of eight (8) bits usually representing a unit of data. .A wordin computer terms is a collection of bits; a word represents the number of bits a computer can handle at a time.

Green marble So, why do computers use binary? .Computer use electricity and all devices that use electricity are said to be BINARYState devices. This is because electric devices have only twostates. The power (electricity) is either ONor OFF; it is either THERE or it is NOT THERE. .Computers use electricity as a combination, a stream of ONs and OFFs, to represent a task. EX.A combination of two ON and one OFF may represent a particular command to a computer. To execute this command the computer must receive an electric signal of

ELECTRICITY . ELECTRICITY . NO-ELECTRICITY.

Green marble So, why do computers use binary? .To help humans understand this a similar system is used. This chosen system is the Binary Number System, which also only has twostates, digits or inputs. Thus that same command may be represented in binary as 110. 110

Green marble Converting to Binary. .Toconvertanumberfromdecimal(base10)tobinary(base2)aseriesofdivisionsbythebase(2 )aredone,andtheremainder(beit1or0)noted.Thefirstremainderachievedisthelastbinary digit.Theresultofthedivisionisusedforthenextdivision. Thisisdoneuntiltheresult(nottheremainder)iszero.

Green marble Converting to Binary. .Thisprocesscanbeseenintheflowchartbelow: This flow chart represents this conversion process. The number Number2 Result = 0 Print the binary number Yes No Remainder Place at front of binary number

Green marble Converting to Binary. .Exampletoconvertnumber10tobinary: 1010. X210 2 = 5 .05 2 = 2 .12 2 = 1 .01 2 = 0 .1X2= 1 0 1 02 .10dividedby2is5,theremainderis0,andthisiswrittendown. .For the next division we use the result, 5 and divide it by 2, the result is 2 and the remainder is 1, this is written in frontof the digit we already have. .Forthenextdivisionweusethelastresult,2anddivideitby2,theresultis1andtheremainde ris0,thisiswritteninfrontofthedigitswealreadyhave. .For the next division we use the last result, 1 and divide it by 2, the result is 0 and the remainder is 1, this is written in frontof the digits we already have. .The last result is 0 and so no more division is done.

Green marble Convert the following to Binary. .1 .2 .3 .8 .12 .14 .21

Green marble Converting from Binary .To convert Binary numbers to Decimal numbers a conversion table can be constructed and can include numbers according to the number of digits in your binary number. The table would basically look like this 23 22 21 20

Green marble Converting from Binary .The equivalents can be written in the second row of the table. 23 22 21 20 8 4 2 1

Green marble Converting from Binary .The binary digits are filled in from the zero-side of the table, the multiplication is done and the results added . 23 22 21 20 8 4 2 1 1 0 1 0 1 x 8 0 x 4 1 x 2 0 x 1 8 0 2 0

+++= 10

Green marble Convert the following to Decimal. .01 .11 .111 .100 .1001 .1101 .10111

Green marble Simple Mathematics .You may be required to add or subtract binary numbers. It may not be efficient to always convert the numbers to decimal then add or subtract them, then convert the result back to binary. The only alternative then is to add or subtract them in binary. .The following tables will help you.

Green marble Simple Mathematics .The following tables will help you. Binary Addition 0 + 0 = 0 0 + 1 = 1 1 + 1 = 10 10 + 1 = 11 1 + 1 + 1 = 11 Binary Subtraction0 -0 = 01 -0 = 11 -1 = 010 -1 = 111 -1 = 10 12plus 12equals 102because 110plus 110 equals 210and 210is equal to 102 Binary Numbers are borrowed and carried just as in base 10 mathematics

Green marble Look at the following and do those that are not completed. 12 +12 102 102+1121012 1112 +112 1102 112+10021112 1002 +12 2 1112 +12 2 1002 +1112 2

Green marble Complements .The complementing method is another way of subtracting binary numbers. .The sum 8 3 is the same as 8 + (-3) and so, if we can represent negative three and then add it to positive eight in binary we would avoid having to subtract positive three directly from positive eight . There are two ways of representing negative number in binary: one s complement and two s complement.

Green marble One s Complement .This is found by simply flippingthe bits of the number, (that is by performing a logical operation on each bit.) That is the same as replacing 0s with 1s and 1s with 0s. .Thus the one s complement of 10001110 is 01110001 NOT

Green marble One s Complement .While adding number are done in the regular way, one s complement uses the following steps to subtract numbers. 1.Convert both numbers to binary (if they are not in binary) 2.Make sure both numbers have the same number of digits (padding) 3.Put the second (that is the negative) number in ones complement notation (flip the bits) 4.Addthe complement to the other number 5.Take the extra bit (which is always 1) from the front and add it to the number. 6.Write the final answer.

Green marble One s Complement .Now to find the value of 5 2 we carry out the following steps. 1.5 = 10122 = 102, 2.Note that for these negations to work both numbers MUST have the same number of digit. If they do not the one with less is padded with 0s at the beginning. Padding must be done before finding the complement.

We pad 102to give it three digits (since 1012has three) and we get 0102. 3.The one s complement of 0102is 1012. 4.We then add this to the binary value of 5 [1012+ 1012 = 10102 ] 5.Our result has an extra bit at the BEGINNING; so we take this from the front and add it to the resultant bits. [0102 + 12 = 0112 ] 6.Thus the correct result is 0112.

If you are not sure about this convert it back to decimal and see.

Green marble Two s Complement .Thisisverysimilartoone scomplementbutisinfactmoreusedthanone scomplement.Itisfoundb yflippingthebitsofthenumber(findingtheone scomplement) andthenadding1totheresult. .Thus the two s complement of 10001110 is equal to (01110001 + 1) which is 01110010.

Green marble Two s Complement .The twos complement uses the same basic steps as ones complement. 1.Convert both numbers to binary (if they are not in binary) 2.Make sure both numbers have the same number of digits (padding) 3.Put the second (or the negative) number in complement. 4.Addthe complement to the other number. 5.Note that the result should have that same number of digits as the factors, thus we would throw awayany extra bit from the front. 6.Write the final answer.

Green marble Two s Complement .Now to find the value of 5 2 we carry out the following steps. 1.5 = 10122 = 102, 2.Note that for these negations to work both numbers MUST have the same number of digit. If they do not the one with less is padded with 0s at the beginning. Padding must be done before finding the complement.

We pad 102to give it three digits (since 1012has three) and we get 0102. 3.The Two s complement of 0102is 101+ 1 = 110 4.We then add this to the binary value of 5 [101 + 110= 1011] 5.Our result has an extra bit at the BEGINNING; so we take this from the front and throw it away. [1011 becomes 011] 6.Thus the correct result is 0112.

If you are not sure about this convert it back to decimal and see.

Green marble Complements -Notes .Thenumbermayhaveanynumberofbinarydigitsaslongastheanswerandeachnumberallhavethe samenumberofdigits. .Thismayseemtedioustoyou,butthecomputerisverygoodwithcomplementingnumbers;thatis flippingbits(itsimplepretendsthatanOFFisanON,andanONisanOFForinotherwordthata1is a0anda0isa1.)Andsodoingthisandaddingthenumbersworksoutfasterandeasierforthecompu tertocalculatesubtractionsthantoactuallydothesubtraction.

Green marble Lets do some work with complements .Write the One s Complement of the following: 1011 1001 010110 011101 01011101

.Write the Two s Complement of the following 01100 01101 0101010 1001000 01011011

Green marble Lets do some work with complements .Calculate the following using the One s Complement method of subtraction. 1011 -011 1001 -1001 010110 -01011 011101 -0111 010111 -01011

Green marble Lets do some work with complements .Calculate the following using the Two s Complement method of subtraction. 1011 -011 1001 -1001 010110 -01011 011101 -0111 010111 -01011

Green marble Parity Bit .A parity bit is an additional bit that is appended to binary data to help the computer to determine if the data is correct, or if it has been tampered with or damaged. Even Parity If the number of onesin the binary data is even then the parity is set to zero (0).

Odd Parity If the number of onesin the binary data is old then the parity is set to one (1). .Thus when the computer checks the number of one bitsin the data and it is even it checks for a parity bit of 0. If the parity bit is 1 then the computer knows that an error occurred and all the binary data was not properly retrieved or checked.

Green marble Padding .Padding was introduced while working with complements. .What is padding?

Green marble Padding .Paddingisaconceptusedtoensurethatanumberhasaspecific numberofdigits byplacing digit(s )withnovalue atthefrontofthenumber.Thatisbyaddingzero(s)tothefrontofthenumbersince hereitwillhavenovalue. 10paddedtohave4-digitsis0010. 10paddedtohave8-digitsis00000010.

S-ar putea să vă placă și