Converting binary numbers to decimal.

Discussion in 'General Cisco Certifications' started by Ozzie, May 9, 2007.

  1. Ozzie

    Ozzie Nibble Poster

    55
    0
    18
    Hi,

    I'm going through some prep questions for my networking course and I've found this question relating to IPv4 Addressing:

    "Convert the binary no. 1010111 to decimal:"

    I also have to convert from decimal to binary.
    Can anyone tell me if there is an easy way to to this?

    Thanks.:blink
     
    WIP: CompTIA A+
  2. mbr2

    mbr2 Bit Poster

    23
    0
    0
    Binary works in mulitpels of 2's hence 128, 64, 32, 16, 8, 4, 2, 1
    So the number 1010111 in binary = 87 in Decimal
    So 00000000 = 0 in decimal & 11111111 = 255

    Hope it help's & i'm also getting my mind round it also.:D
     
    Certifications: ECDL & A+
    WIP: CCNA
  3. Tinus1959

    Tinus1959 Gigabyte Poster

    1,539
    42
    106
    There is a far more easier way to do this.
    In every numbersystem, octal, decimal, hexadecimal or binairy, when you add a zero, you in fact multiply by the basenumber.
    What does this mean?
    Lets look at a decimal number first.
    lets say we take 6. When we place a zero behind it, we multiply by ten getting 60. Another zero to it makes 600.
    When we take a number as 6384 and we look at the leftmost digit it reads 6.
    When we shift 1 place to the right we need to multiply by ten and add the 3 which is sitting there, getting 63.
    Another shift gives 630 plus 8 makes 638 and so on.
    The beaty off this system is that it works on every numberbase. Working octal, just multiply by 8. Working hexadecimal, multiply by 16 and, yiou quest it, working binairy, muliply by two.
    So 101 is 5
    1010 is 10
    10100 is 20
    101000 is 40
    If you "add" a zero, just multiplyby two, if it's a one, multiply by two and add one.
    Lets get your number again:
    1010111
    First figure reads 1.
    Shift 1 position (10) 1 times two makes 2
    Shift again (101) 2 times 2 plus 1 gives 5.
    Shift again (1010) 5 times 2 makes 10
    Shift (10101) 10 times 2 plus 1 makes 21
    Shift (101011) 21 times 2 plus 1 makes 43
    Shift (1010111) 43 times 2 plus 1 makes 87.
    DONE
    Simple!
     
    Certifications: See my signature
    WIP: MCSD, MCAD, CCNA, CCNP
  4. Mitzs
    Honorary Member

    Mitzs Ducktape Goddess

    3,286
    85
    152
    Certifications: Microcomputers and network specialist.
    WIP: Adobe DW, PS
  5. Raffaz

    Raffaz Kebab Lover Gold Member

    2,976
    56
    184
    Now im confused, the other ways easier for me :oops:
     
    Certifications: A+, MCP, MCDST, AutoCAD
    WIP: Rennovating my house
  6. Quarky

    Quarky Byte Poster

    113
    4
    39
    Tinus - Top notch number working tip for anyone wanting an easy way to work out number systems !!

    Stick with it Raffaz 'ol pol - if you don't get it at first, its a very quick method once you get it. You can literally work out the example 1010111 in a couple of seconds.

    Very useful to know - cheers Tinus.

    :D
     
    Certifications: A+,270,271,272 (MCDST)
    WIP: Master CIW
  7. Raffaz

    Raffaz Kebab Lover Gold Member

    2,976
    56
    184
    Yeah, ive sussed it now, i just keep losing count lol
     
    Certifications: A+, MCP, MCDST, AutoCAD
    WIP: Rennovating my house
  8. Tinus1959

    Tinus1959 Gigabyte Poster

    1,539
    42
    106
    My methode is realy quicker, it works allways (back and forwards (that is bin to dec and dec to bin)) is so easy you can do it by hard. You only need to "see" the trick.
    It is just a bit difficult to put it to paper in just a few lines.
    If you want, I'll explain again in a more extended way using different sizes in fonts to make it more clear.
    Just let me know.
     
    Certifications: See my signature
    WIP: MCSD, MCAD, CCNA, CCNP
  9. Headache

    Headache Gigabyte Poster

    1,092
    9
    85

    Yes please.
     
    Certifications: CCNA
    WIP: CCNP
  10. Tinus1959

    Tinus1959 Gigabyte Poster

    1,539
    42
    106
    Why do I have such a big mouth:rolleyes: :biggrin

    Okay here it comes. Bin numbers are in red.
    first the simple basics.
    If we take a number as 11 we all see that this stands for 3 in dec.
    What happens when we put a zero behind it?
    110 is 6.
    Apperently it got multiplied by 2.
    and when we put another zero behind?
    1100 is 12.
    It got multiplied by 2 again.
    Is this behaviour a coincidence? Well, the base for binairy calculations is 2; we only have two options, 1 and 0; so it it might just be a "system".
    Lets make a small switch to the decimal world.
    Take a number as 4.
    Put a zero behind it and we get 40. It got multilpied by 10. Coincidence? The base for the decimal system is 10. We have 10 different options: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. That why the system is called the decimal system: deci is Latin for 10.
    Does this work al the time?
    Lets see: 6 -> 60 is multiplication by 10.
    9 -> 90 is multiplication by 10.
    43 -> 430 is multiplication by 10.
    It seems to be a rule that adding a zero in the decimal system means multiply by 10.
    What if the addition is not 0 but something else?
    4 -> 46?
    Well here we multiplied by 10 and added 6 extra.
    46 means 4 times 10 plus 6.

    Back to the binairy system.
    Lets say we have a binairy number as:
    1001101101001 (Notice I have a few more digits than 8:biggrin )
    Pretend we cover the number with a sheet of paper (the covered numbers are in blue)
    We have then: 1001101101001
    The whole number is covered so we see nothing.
    Now start sliding the paper sheet till the left most digit is revealed 1001101101001
    What do we see? Right: one.
    Now with every slide of the paper we just multiply by two and adding the digit that is revealed.
    Slide two:
    1001101101001
    We had 1. now muliply by two and add 0 (revealed digit). We end up with 2.
    Slide again:
    1001101101001
    We had two, we multiply by two and add (again) 0. That makes 4.
    Slide again:
    1001101101001
    we had 4, multiply by 2 and add 1 (revealed digit). That makes 9.
    Slide again:
    1001101101001
    We had 9,multiply by 2 and add 1. Makes 19.
    (one more for clearaty)Slide again:
    1001101101001
    We had 19, multiply by two and add 0 (revealed digit). This makes 38.
    Speeding up the rest:
    38 * 2 + 1 makes 77
    77 * 2 + 1 makes 155
    155 * 2 + 0 makes 310
    310 * 2 + 1 makes 621
    621 * 2 + 0 makes 1242
    1242 * 2 + 0 makes 2484
    2484 * 2 + 1 makes 4969.
    Done. No digits left to proces.

    Nice extra: it also works in other counting systems.
    Octal: Base is 8
    What is 2534 octal in decimal?
    first digit is 2
    slide! 2 * 8 + 5 makes 21
    slide! 21 * 8 + 3 makes 171
    slide! 171 * 8 + 4 makes (ehhhh) 1372.

    Works also in hex: just the base is now 16.
    ABE
    First digit is A is 10.
    slide! 10 * 16 + 11 makes 171
    slide! 171 * 16 + 14 makes 2750.

    The other way round (decimal to bin) is just the opposite. Instead of multiplication, you use division and write down the remainder.

    Example
    135. Divide by 2 gives 67 remain 1 (last digit is 1)
    67 divide by 2 gives 33 remain 1 (one but last digit is 1)
    33 divide by 2 gives 16 remain 1 (two but last digit is 1)
    16 by 2 is 8 remain 0 (three but last digit is 0)
    8 by 2 is 4 remain 0 (again a zero)
    4 by 2 is 2 remain 0 (zero again)
    2 by 2 is 1 remain 0 (and again)
    1 by 2 is zero remain 1. (Most left digit is 1). We ended on zero, so there is nothing left to divide; we are done.
    The binairy form for 135 is 10000111

    I could even prove the methode using algebra, but that would be overdone.

    Try it a few times. When you get the trick you'll never use the other methode anymore.
     
    Certifications: See my signature
    WIP: MCSD, MCAD, CCNA, CCNP
  11. Headache

    Headache Gigabyte Poster

    1,092
    9
    85
    Big thanx, Tinus.

    I don't fully get it yet, but I'll play around with it in a while and see. Did you know that if you made a video of this system and put it on the market you can actually make some money ?
     
    Certifications: CCNA
    WIP: CCNP
  12. Headache

    Headache Gigabyte Poster

    1,092
    9
    85
    Holy Christ !

    I had a go at the binary conversion bit and it works like a dream ! I can see how this would be a lot easier that adding 128 to 64 to 16 to 4 etc etc. With a little practice you might even be able to narrow the typical binary question down to about two or three seconds.

    Thank Tinus.

    Now lets make that video and go make us some big bucks !
     
    Certifications: CCNA
    WIP: CCNP
  13. Raffaz

    Raffaz Kebab Lover Gold Member

    2,976
    56
    184
    Nice post mate.:)
     
    Certifications: A+, MCP, MCDST, AutoCAD
    WIP: Rennovating my house
  14. Tinus1959

    Tinus1959 Gigabyte Poster

    1,539
    42
    106
    Thats the whole purpose of: speed. If you sit the cisco exams, you'll need the time. If you can make the conversion is seconds and same time this way you'll have more time for the other questions. Also, its universal. You'll only have to remember 1 systems.
    If you want more info on doing calculations in super fast way, do a search on Vedic Mathematics.
    You'll be surprised.
    I don't think we will get big bucks:biggrin
     
    Certifications: See my signature
    WIP: MCSD, MCAD, CCNA, CCNP
  15. Bambino1506

    Bambino1506 Megabyte Poster

    594
    8
    64
    Great post Tinus, that has really helped me !!!

    Repped.

    Here's a virtual beer 2 :beers2
     
    Certifications: MCP,MCDST,MCSA
    WIP: CCA
  16. Mathematix

    Mathematix Megabyte Poster

    969
    35
    74
    You guys really make life difficult for yourselves. The way to quickly convert from binary to decimal would be to simply add the powers of 2 that are set to '1'. In decimal we use the exact same system:

    10^0 = 1
    10^1 = 10
    10^2 = 100
    10^3 = 1,000
    ...
    10^10 = 10,000,000,000

    so we can conclude that for 10^n where 10 is the base and 'n' the index, the index reprents the number of zeros that follows the '1' - as an easy way to remember. So when we have a number like 1,256 we are saying:

    1 x 10^3 = 1,000 (10 x 10 x 10 x 1)
    +
    2 x 10^2 = 200 (10 x 10 x 2)
    +
    5 x 10^1 = 50 (10 x 5)
    +
    6 x 10^0 = 6 (1 x 6)

    for the grand sum of 1,256. Binary works in the same, but the base changes giving different values to its powers:

    2^0 = 1
    2^1 = 2
    2^2 = 4
    2^3 = 8
    2^4 = 16
    2^5 = 32
    2^6 = 64

    So for your number we are 1010111 we are only interested in the values set to '1', so we have:

    1 x 64 + 0 x 32 + 1 x 16 + 0 x 8 + 1 x 4 + 1 x 2 + 1 x 1,

    or removing the redundant calculations:

    1 x 64 + 1 x 16 + 1 x 4 + 1 x 2 + 1 x 1

    and making more concise:

    64 + 16 + 4 + 2 + 1 = 87

    And there you have it! :biggrin
     
    Certifications: BSc(Hons) Comp Sci, BCS Award of Merit
    WIP: Not doing certs. Computer geek.
  17. Ozzie

    Ozzie Nibble Poster

    55
    0
    18
    Thanks for your help everyone. Now I can convert binary in seconds as well.

    BIG THUMBS UP to tinus.:thumbleft
    Thats just what I was looking for. You put alot of effort into those posts. Cheers:rocks
     
    WIP: CompTIA A+

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.