Results 1 to 5 of 5

Thread: For those of you who don't understand non-Base10 numbers....

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    London, ON
    Posts
    40

    Smile

    As we all no binary is a system of counting using only 0's and 1's. But how does this work? Well imagine an odometer (distance thingy in your car) that after it reaches a max number on one wheel it flips the one next to it one position. The base of the counting system denotes the number of positions on each. We use base 10 (ie. DECimal, DEC meaing 10) and there are 10 possible positions for our odometer 0,1,2,3,4,5,6,7,8,9. To convert a number from its base to base ten:
    1) take a number
    2) multiply its by its value
    3) then by its base to the power of its' distance from the decimal point (NB the number to the left of the decimal point is distance 0, the one to the right is -1)
    4) add it to a running total
    5) do with all numbers

    EXAMPLE USING HEXADECIMAL

    number = A03D.C
    1) A
    2) A = 10
    3) Base = 16
    distance = 3
    10 * 16^3 = 40960
    4) Runing Total = 40960
    1) 0
    2) 0 = 0
    3) base = 16
    distance = 2
    0 * 16^2 = 0
    4) RT = 40960 + 0 = 40960
    1) 3
    2) 3 = 3
    3) distance = 1
    3 * 16^1 = 48
    4) RT = 40960 + 48 = 41008
    1) D
    2) D = 13
    3) distance = 1
    13 * 16^0 = 13
    4) RT = 356128 + 208 = 41021
    1) C
    2) C = 12
    3) distance = -1
    12 * 16^-1 = 0.75
    4) RT = 41021.75
    Therefore A03D.C = 41021.75
    (check it on your WinCalculator)
    you can see that it is neater and shorter.
    for other bases replace 26 with the appropriate base #.
    Please respond if you found this helpful or want clarification.
    Visual Basic 6 Professional Edition
    Captain Pinko

    also:
    Turbo Pascal, Turing, QBasic

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Here's something you could have use for, you could convert from between whatever bases. The elements used beyond 9 continues on A-Z and [\] and so on
    Code:
    Function Base2Dec(val$, base%): Dim n%, a() As Byte
        a = StrConv(UCase(val), vbFromUnicode)
        For n = 1 To Len(val)
            Base2Dec = CDec(Base2Dec + (a(n - 1) - 48 + 7 * (a(n - 1) > 64)) * base ^ (Len(val) - n))
        Next n
    End Function
    Function Dec2Base$(val, base%): Dim n%, s
        For n = 0 To 100
            s = Int(val / base ^ n)
            If s = 0 Then Exit For
            s = s - Int(s / base) * base 's mod base
            Dec2Base = Chr(s + 48 - 7 * (s > 9)) & Dec2Base
        Next n
    End Function
    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.

  3. #3
    Guest
    cool, I have been looking for code like that for a long time

  4. #4
    Addicted Member
    Join Date
    May 2000
    Location
    Grand Rapids, MI
    Posts
    231
    I think it might be usefull to understand the base numbers in binary

    1 - 1
    2 - 10
    4 - 100
    8 - 1000
    16- 10000
    32- 100000
    64- 1000000
    128-10000000
    256-100000000
    512-1000000000
    1024-10000000000

    each binary increases to another digit
    you add one to the right, you move it up until you get to the end for example (i'm only going to do the first few)

    1
    10
    11
    100
    101
    110
    111
    1000
    1001
    1010
    1100
    1101
    1110
    1111
    10000

    also keep note all the way upto 256 , hexidecimal remains 2 digit ( Octal stops at 8 )
    hexidecimals are used mainly in representation, because the digits can remain small even if the numbers get big.

    1 - 1 - 1
    2 - 10 - 2
    4 - 100 - 4
    8 - 1000 - 8
    16 - 10000 - 10
    32 - 100000 - 20
    64 - 1000000 - 40
    128 - 10000000 - 80
    256 - 100000000 - 100 ( 255 is FF, numerically it goes from 0-FF for 0-255, which still makes a count of 256)

    see the patern in each base?

    up til 255 Hex keeps a consitant 2 digit representation.
    so for each binary step it adds a digit, for each hexidecimal step, it doubles itself(or would seem like it doubles itself if you looked at it from a 10base perspective)

    but the source codes above are good if you just want to get the representation conversion without understanding it all (btw I did not use a calculator or anything, it's from memory, if you want to check my work go ahead)
    -Karl Blessing aka kb244{fastHACK}
    [email protected]

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    London, ON
    Posts
    40

    Talking Thanx for the conversion code....

    Thanx for replying but the point was to explain how they work. And as for memorizing the binary it is not all that hard. Just take number that is two to the power of XXXXX and stick a 1 in that spot (eg. 512 = 2^9 so = 100000000 in binary)
    Visual Basic 6 Professional Edition
    Captain Pinko

    also:
    Turbo Pascal, Turing, QBasic

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