Results 1 to 10 of 10

Thread: base conversion

  1. #1

    Thread Starter
    Fanatic Member bugzpodder's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    787

    base conversion

    convert 9.75 to base two. there are a quiet few methods of doing it, one of them is really nice! so if you have a method not posted here, by all means post it!
    Massey RuleZ! ^-^__Cheers!__^-^ Massey RuleZ!


    Did you know that...
    The probability that a random rational number has an even denominator is 1/3 (Salamin and Gosper 1972)? This result is independently verified by me (2002)!

  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    1001.1001011

  3. #3

    Thread Starter
    Fanatic Member bugzpodder's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    787
    no
    Massey RuleZ! ^-^__Cheers!__^-^ Massey RuleZ!


    Did you know that...
    The probability that a random rational number has an even denominator is 1/3 (Salamin and Gosper 1972)? This result is independently verified by me (2002)!

  4. #4
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    /me doesn't know how to represent a decimal in binary.


  5. #5
    Fanatic Member sql_lall's Avatar
    Join Date
    Jul 2002
    Location
    Up Above (i.e. AUS)
    Posts
    571

    Easy...

    9.75 = 9 + 3/4
    = 8 + 1 + 1/2 + 1/4
    = 1001.11
    sql_lall

  6. #6

    Thread Starter
    Fanatic Member bugzpodder's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    787
    yep right answer. also, 9.75=39/4=100111/100=1001.11
    Massey RuleZ! ^-^__Cheers!__^-^ Massey RuleZ!


    Did you know that...
    The probability that a random rational number has an even denominator is 1/3 (Salamin and Gosper 1972)? This result is independently verified by me (2002)!

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    9%2=1
    9\2=4
    4%2=0
    4\2=2
    2%2=0
    2\2=1
    1%2=1
    do integer division with radix until you get 1, append the modulo to string
    0.75 * 2 = 1.5
    0.5 * 2 = 1
    0.11
    I don't know if this works with other than base 2, multiply with with two until you get 1, if you get more than 1, append 1 in the string, subtract 1 from the result and start over, otherways append 0 to string.

    1001.11
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    Addicted Member
    Join Date
    Aug 2002
    Location
    Windsor, Ontario's City of Pollution
    Posts
    165
    The division by 100 was originally done by long division!
    Merry Math Making!

  9. #9

    Thread Starter
    Fanatic Member bugzpodder's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    787
    Not many ppl could come up with such an ingenious method!
    Massey RuleZ! ^-^__Cheers!__^-^ Massey RuleZ!


    Did you know that...
    The probability that a random rational number has an even denominator is 1/3 (Salamin and Gosper 1972)? This result is independently verified by me (2002)!

  10. #10
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    Convert fractions by muliplying by the new Radix.

    Convert decimal .375 to binary.

    Multiply by two: 0.75
    Multiply fractional part by two: 1.50
    Multiply fractional part by two: 1.00
    Fractional part is zero, you are finished.

    Take integer parts of each product in order: .011

    If you try the above with a value like .37, you will never get exactly zero for the fractional part because .37 is a never ending binary fraction.

    To convert integers, divide by radix and use remainder for the converted digits.

    Convert decimal 28 to binary.

    28/2 = 14, Remainder zero.
    14/2 = 7, Remainder zero
    7/2 = 3, remainder one
    3/2 = 1 remainder one
    1/2 = 0 Remainder one. You are done since quotient is zero.

    Take remainders in reverse order: 11100

    The above works for converting from any radix to any other, but requires doing arithmetic with some radix other than ten for some conversions. For example.

    Octal .32 to decimal (Note that Ten = octal 12)

    Ten * .32 (octal arithmetic) = 4.04
    Ten * .04 = 0.50
    Ten * .50 = 6.2
    Ten * .2 = 2.4
    Ten * .4 = 5.0

    Decimal value is .40625

    Use decimal arithmetic to convert back to octal.

    Eight * .40625 = 3.25
    Eight * .25 = 2.000

    Result is octal .32
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width