+ All Categories
Home > Documents > IT-01Binary for CXC

IT-01Binary for CXC

Date post: 07-Apr-2018
Category:
Upload: giovanni-dappa-hosang
View: 215 times
Download: 0 times
Share this document with a friend

of 32

Transcript
  • 8/4/2019 IT-01Binary for CXC

    1/32

    Green marbleBinary For CXC

    S. Edwards

  • 8/4/2019 IT-01Binary for CXC

    2/32

    Green marbleWhat is binary?

    .Binary is simply a number system based on two, that is anumber system that has only two digits and both being lessthan two. The Binary in computing is the same Binary in

    mathematics; its just that it actually has an applied use..Every day we count in or use a number system based onten, this is called decimal. Computers also count in and usea number system, but they usually use one based on twonot ten, in other words binary..In decimal (base 10) there are ten digits from 0 to 9, andthese are combined to form many numbers. In binary (base2) there are two numbers, 0 and 1, and they are combinedto form many numbers.

  • 8/4/2019 IT-01Binary for CXC

    3/32

    Green marbleWhat 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 beingused, is written subscript (just below) the number.

  • 8/4/2019 IT-01Binary for CXC

    4/32

    Green marbleWhat is a Bit, Byte & Word?.A bitis simply a Binary Digit, a single unitof a binary number..A byteis a collection of eight (8) bitsusually representing a unit of data.

    .A wordin computer terms is a collection ofbits; a word represents the number of bits acomputer can handle at a time.

  • 8/4/2019 IT-01Binary for CXC

    5/32

    Green marbleSo, why do computers usebinary?

    .Computer use electricity and all devices that useelectricity are said to be BINARYState devices.

    This is because electric devices have only twostates. The power (electricity) iseither ONor OFF;

    it is either THERE or it is NOT THERE..Computers use electricity as a combination, astream of ONs and OFFs, to represent a task.EX.A combination of two ON and one OFF mayrepresent a particular command to a computer. Toexecute this command the computer must receive anelectric signal of

    ELECTRICITY . ELECTRICITY . NO-ELECTRICITY.

  • 8/4/2019 IT-01Binary for CXC

    6/32

    Green marbleSo, why do computers usebinary?.To help humans understand this a similarsystem is used. This chosen system is theBinary Number System, which also only

    has twostates, digits or inputs. Thus thatsame command may be represented inbinary as 110.

    110

  • 8/4/2019 IT-01Binary for CXC

    7/32

    Green marbleConverting to Binary.

    .Toconvertanumberfromdecimal(base10)tobinary(base2)aseriesofdivisionsbythebase(2)aredone,andtheremainder(beit1or0)noted.Thefirstremainderachievedisthelastbinarydigit.Theresultofthedivisionisusedforthenextdivision.

    Thisisdoneuntiltheresult(nottheremainder)iszero.

  • 8/4/2019 IT-01Binary for CXC

    8/32

    Green marbleConverting to Binary.

    .Thisprocesscanbeseenintheflowchartbelow:

    This flow chart represents this conversion process.The numberNumber2Result = 0Print the binarynumber

    YesNo

    Remainder

    Place at front ofbinary number

  • 8/4/2019 IT-01Binary for CXC

    9/32

    Green marbleConverting 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 theresult, 5 and divide it by 2, the result is2 and the remainder is 1, this is writtenin frontof the digit we already have.

    .Forthenextdivisionweusethelastresult,2anddivideitby2,theresultis1andtheremainderis0,thisiswritteninfrontofthedigitswealreadyhave.

    .For the next division we use the last result, 1 and divide it by 2, the resultis 0and 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.

  • 8/4/2019 IT-01Binary for CXC

    10/32

    Green marbleConvert the following toBinary.

    .1

    .2

    .3

    .8

    .12

    .14

    .21

  • 8/4/2019 IT-01Binary for CXC

    11/32

    Green marbleConverting from Binary

    .To convert Binary numbers to Decimal numbers aconversion table can be constructed and can includenumbers according to the number of digits in your

    binary number. The table would basically look likethis

    23

    22

    21

    20

  • 8/4/2019 IT-01Binary for CXC

    12/32

    Green marbleConverting from Binary

    .The equivalents can be written in the second row ofthe table.

    23

    22

    21

    20

    8

    4

    2

    1

  • 8/4/2019 IT-01Binary for CXC

    13/32

    Green marbleConverting from Binary

    .The binary digits are filled in from the zero-side ofthe table, the multiplication is done and the resultsadded .

    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

  • 8/4/2019 IT-01Binary for CXC

    14/32

    Green marbleConvert the following toDecimal.

    .01

    .11

    .111

    .100

    .1001

    .1101

    .10111

  • 8/4/2019 IT-01Binary for CXC

    15/32

    Green marbleSimple Mathematics

    .You may be required to add or subtractbinary numbers. It may not be efficient toalways convert the numbers to decimal then

    add or subtract them, then convert the resultback to binary. The only alternative then isto add or subtract them in binary..The following tables will help you.

  • 8/4/2019 IT-01Binary for CXC

    16/32

    Green marbleSimple 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 = 1012plus 12equals102because 110plus110 equals 210and 210is equal to 102

    Binary Numbers areborrowed and carriedjust as in base 10mathematics

  • 8/4/2019 IT-01Binary for CXC

    17/32

    Green marbleLook at the following and dothose that are not completed.

    12

    +12

    102

    102+11210121112

    +112

    1102

    112+10021112

    1002

    +12

    2

    1112

    +12

    2

    1002

    +1112

    2

  • 8/4/2019 IT-01Binary for CXC

    18/32

    Green marbleComplements.The complementing method is another way ofsubtracting binary numbers..The sum 8 3 is the same as 8 + (-3) and so, if wecan represent negative three and then add it to

    positive eight in binary we would avoid having tosubtract positive three directly from positiveeight. There are two ways of representing negativenumber in binary:ones complement andtwos complement.

  • 8/4/2019 IT-01Binary for CXC

    19/32

    Green marbleOnes Complement

    .This is found by simply flippingthe bits ofthe number, (that is by performing a logical NOToperation on each bit.) That is the same as

    replacing 0s with 1s and 1s with 0s..Thus the ones complement of 10001110 is01110001

  • 8/4/2019 IT-01Binary for CXC

    20/32

    Green marbleOnes Complement

    .While adding number are done in the regular way,ones complement uses the following steps tosubtract 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 onescomplement notation (flip the bits)4.Addthe complement to the other number5.Take the extra bit (which is always 1) from the front andadd it to the number.6.Write the final answer.

  • 8/4/2019 IT-01Binary for CXC

    21/32

    Green marbleOnes 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 with0s at the beginning. Padding must be done before finding thecomplement.

    We pad 102to give it three digits (since 1012has three) and we get 0102.

    3.The ones 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.

  • 8/4/2019 IT-01Binary for CXC

    22/32

    Green marbleTwos Complement.Thisisverysimilartoonescomplementbutisinfactmoreusedthanonescomplement.Itisfoundbyflippingthebitsofthenumber(findingtheonescomplement)andthenadding1totheresult..Thus the twos complement of 10001110 is

    equal to (01110001 + 1) which is 01110010.

  • 8/4/2019 IT-01Binary for CXC

    23/32

    Green marbleTwos Complement

    .The twos complement uses the same basic steps asones 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 ofdigits as the factors, thus we would throw awayanyextra bit from the front.6.Write the final answer.

  • 8/4/2019 IT-01Binary for CXC

    24/32

    Green marbleTwos 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 with0s at the beginning. Padding must be done before finding thecomplement.

    We pad 102to give it three digits (since 1012has three) and we get 0102.

    3.The Twos complement of 0102is 101+ 1 = 1104.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.

  • 8/4/2019 IT-01Binary for CXC

    25/32

    Green marbleComplements -Notes

    .Thenumbermayhaveanynumberofbinarydigitsaslongastheanswerandeachnumberallhavethesamenumberofdigits..Thismayseemtedioustoyou,butthecomputerisverygoodwithcomplementingnumbers;thatis

    flippingbits(itsimplepretendsthatanOFFisanON,andanONisanOFForinotherwordthata1isa0anda0isa1.)Andsodoingthisandaddingthenumbersworksoutfasterandeasierforthecomputertocalculatesubtractionsthantoactuallydothesubtraction.

  • 8/4/2019 IT-01Binary for CXC

    26/32

    Green marbleLets do some work withcomplements.Write the OnesComplement of thefollowing:

    1011100101011001110101011101

    .Write the TwosComplement of thefollowing0110001101

    0101010

    1001000

    01011011

  • 8/4/2019 IT-01Binary for CXC

    27/32

    Green marbleLets do some work withcomplements.Calculate the following using the OnesComplement method of subtraction.1011 -011

    1001 -1001010110 -01011011101 -0111010111 -01011

  • 8/4/2019 IT-01Binary for CXC

    28/32

    Green marbleLets do some work withcomplements

    .Calculate the following using the TwosComplement method of subtraction.

    1011 -0111001 -1001010110 -01011011101 -0111010111 -01011

  • 8/4/2019 IT-01Binary for CXC

    29/32

    Green marbleParity Bit.A parity bit is an additional bit that is appended to binary datato help the computer to determine if the data is correct, or if ithas been tampered with or damaged.

    Even Parity

    If the number of onesin the binary data is even then the parity is set tozero (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 thedata and it is even it checks for a parity bit of 0. If the parity bitis 1 then the computer knows that an error occurred and all thebinary data was not properly retrieved or checked.

  • 8/4/2019 IT-01Binary for CXC

    30/32

    Green marblePadding.Padding was introduced while workingwith complements..What is padding?

  • 8/4/2019 IT-01Binary for CXC

    31/32

    Green marblePadding.Paddingisaconceptusedtoensurethatanumberhasaspecificnumberofdigitsbyplacingdigit(s)withnovalueatthefrontofthenumber.Thatisbyaddingzero(s)tothefrontofthenumbersincehereitwillhavenovalue.10paddedtohave4-digitsis0010.

    10paddedtohave8-digitsis00000010.

  • 8/4/2019 IT-01Binary for CXC

    32/32


Recommended