Converting numbers to binary

GHOSTRIDER2016GHOSTRIDER2016 ■■□□□□□□□□ Posts: 35Member ■■□□□□□□□□
Guys,

When it comes to converting numbers to binary i read that you keep dividing the number by 2 and any remainders just come out as 1 so imagine that the number 500 in binary is

500/2 = 250 = 0
250/2 = 125 = 0
125/2 = 62.5 = 1 (reminder)
62.5/2 = 31.2 =1
31.2/2 = 15 = 1

etc you keep dividing until you have no more numbers to divide and the number will be from bottom to top is this correct ?

Many thanks

Comments

  • CryptrotTheWarlockCryptrotTheWarlock ■□□□□□□□□□ Posts: 6Member ■□□□□□□□□□
    You treat it as _integer_ division. You do not carry forward the remainder each time, in this case / is division and % is what's caled modulus (the remainder when dividing in integers). So 125/2 = 62 (You're only looking at the integer result) and then 125%2 = 1 (This gets you your remainder of 1).

    500/2 = 250, 500%2 = 0 -> 0
    250/2 = 125, 250%2 = 0 -> 0
    125/2 = 62, 125%2 = 1 -> 1
    62/2 = 31, 62%2 = 0 -> 0
    31/2 = 15, 31%2 = 1 -> 1
    15/2 = 7, 15%2 = 1 -> 1
    7/2 = 3, 7%2 = 1 -> 1
    3/2 = 1, 3%2 = 1 -> 1
    1/2 = 0, 1%2 = 1 -> 1

    Now you take the numbers and work your way from bottom up, in this case 500(base10) is 111110100(base2).

    If you think back to grade school before you knew what decimals and fractions were you were probably taught intger division with the R for remainder notation, it's the exact same concept here. You can _only_ have a remainder of 1 or 0 when dividing by 2 and that remainder is what gives you the value in the new base. I'm sorry if I am explaining this oddly, but it's much easier to just work through one or two. This works for other bases as well (e.g. you can convert a number from base 10 to base 8 by dividing by 8 and using the remainders for the new digits)

    I guess the important thing is don't use 62.5 in your next operation, use 62. Don't look at 125/2 as 62.5 think of it as 62R1 and the R1 is what gives you the binary digit (or bit) for that field and 62 is what you bring forward (the next bit is a 0 since 62/2 = 31R0 which is where you went wrong).
  • NavyMooseCCNANavyMooseCCNA CCNA R&S, ITIL, Security+ ZZ9ZZAPosts: 543Member ■■■■□□□□□□
    I just had spasms with flashbacks to grade school math class....not a pretty sight.

    Being math challenged, I'm having trouble following this. I learned a different way which makes sense, even with my trouble with numbers.

    'My dear you are ugly, but tomorrow I shall be sober and you will still be ugly' Winston Churchil

  • scaredoftestsscaredoftests Security +, ITIL Foundation, MPT, EPO, ACAS, HTL behind youPosts: 2,705Mod Mod
    Being a dyslexic, my brain is exploding. LOL
    Never let your fear decide your fate....
  • GHOSTRIDER2016GHOSTRIDER2016 ■■□□□□□□□□ Posts: 35Member ■■□□□□□□□□
    Thanks for your detailed response i am going to try and absorb this its tough stuff icon_sad.gif
    You treat it as _integer_ division. You do not carry forward the remainder each time, in this case / is division and % is what's caled modulus (the remainder when dividing in integers). So 125/2 = 62 (You're only looking at the integer result) and then 125%2 = 1 (This gets you your remainder of 1).

    500/2 = 250, 500%2 = 0 -> 0
    250/2 = 125, 250%2 = 0 -> 0
    125/2 = 62, 125%2 = 1 -> 1
    62/2 = 31, 62%2 = 0 -> 0
    31/2 = 15, 31%2 = 1 -> 1
    15/2 = 7, 15%2 = 1 -> 1
    7/2 = 3, 7%2 = 1 -> 1
    3/2 = 1, 3%2 = 1 -> 1
    1/2 = 0, 1%2 = 1 -> 1

    Now you take the numbers and work your way from bottom up, in this case 500(base10) is 111110100(base2).

    If you think back to grade school before you knew what decimals and fractions were you were probably taught intger division with the R for remainder notation, it's the exact same concept here. You can _only_ have a remainder of 1 or 0 when dividing by 2 and that remainder is what gives you the value in the new base. I'm sorry if I am explaining this oddly, but it's much easier to just work through one or two. This works for other bases as well (e.g. you can convert a number from base 10 to base 8 by dividing by 8 and using the remainders for the new digits)

    I guess the important thing is don't use 62.5 in your next operation, use 62. Don't look at 125/2 as 62.5 think of it as 62R1 and the R1 is what gives you the binary digit (or bit) for that field and 62 is what you bring forward (the next bit is a 0 since 62/2 = 31R0 which is where you went wrong).
  • GHOSTRIDER2016GHOSTRIDER2016 ■■□□□□□□□□ Posts: 35Member ■■□□□□□□□□
    Being a dyslexic, my brain is exploding. LOL

    I got scared when CryptrotTheWarlock posted this it was like wow my brain is about to blow up
Sign In or Register to comment.