Need help converting to a decimal value

Discussion in 'Mac Programming' started by cybrscot, Mar 25, 2011.

  1. cybrscot macrumors 6502

    cybrscot

    Joined:
    Dec 7, 2010
    Location:
    Somewhere in Southeast Asia
    #1
    Book:
    Give the decimal value of each of the following integer constants.
    a) 077

    I'm assuming this 077 number is in Octal form because it uses only digits 0 and 7, and Octal requires 0-7 as well.

    The book doesn't explain how to convert, but it does show an example.
    Example:
    Octal 237
    Decimal Number: 2 x 8(2) + 3 x 8(1) + 7 x 8(0) = 128 + 24 + 7 = 159

    I can see a pattern in the example we're using the numbers 237 and multiplying each by Octal 8, but then 8 has a power, I don't know how to determine what power to use??

    My number of 077 would be something like:
    0 x 8(?) + 7 x 8(0) + 7 x 8(0)= I put 0's because I don't know how to determine what power to use. Do we always use powers 2-1-0??
    Then it would be 64 + 56 + 0 = 120, is that correct? I'm just guessing here based on the pattern in the books example.

    I looked on the web and found another example that I don't understand.
    Example: (makes no sense to me) they don't explain in words how to solve this.

    octal8 -> decimal

    258 -> decimal

    81 80

    8 1
    2 5
    16+5 = 21

    158 -> 21
     
  2. dmi macrumors regular

    Joined:
    Dec 21, 2010
    #2
    What powers do you use when interpreting a decimal number?
    77 in decimal is
    7 * 10(1) + 7 * 10(0) = 70 + 7
    so
    077 in octal is
    7 * 8(1) + 7 * 8(0) = 56 + 7
     
  3. TastyCocoa macrumors newbie

    TastyCocoa

    Joined:
    Mar 21, 2011
    #3
    And just to add to that

    56.13 = 5*10^(1) + 6*10(0) + 1*10^(-1) + 3*10(-2)
     
  4. Bill McEnaney, Mar 25, 2011
    Last edited: Mar 25, 2011

    Bill McEnaney macrumors 6502

    Joined:
    Apr 29, 2010
    #5
    The decimal numbering system is the base 10 numbering system. In a decimal number, the rightmost place value is 1. Ten will be the place-value of the next place to the left. The place-value of the third place to the left will be 100, and so forth. In any numbering, the current place-value will be the base * the previous place-value. The first place is always the rightmost place, and its place-value is always 1.

    An octal 213 = 3 + 8 + 128. That's a decimal 139.
     
  5. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #6
    You can perform conversions from any number system in the same way. Each position has a value based on it's distance from the . separating the whole portion from the fractional portion (decimal point in decimal). The position just to the left of this point is the 0th position, and this goes up as you move left and down as you move right, so:

    1076.235

    Position 3: 1
    Position 2: 0
    Position 1: 7
    Position 0: 6
    Position -1: 2
    Position -2: 3
    Position -3: 5

    Each position's value is the base of the numbering system raised to the power of this position, so:
    1*(x^3) + 0*(x^2) + 7*(x^1) + 6*(x^0) + 2*(x^-1) + 3*(x^-2) + 5*(x^-3)

    so let's say this is an octal value:
    1*(8^3) + 0*(8^2) + 7*(8^1) + 6*(8^0) + 2*(8^-1) + 3*(8^-2) + 5*(8^-3)

    1*512 + 0*64 + 7*8 + 6*1 + 2*(1/8) + 3*(1/64) + 5*(1/512)
    512 + 0 + 56 + 6 + 1/4 + 3/64 + 5/512
    574 + 128/512 + 24/512 + 5/512
    574 + 157/512
    ~574.306641 base 10 equals (approximately) 1076.235 base 8

    Chances are the bases you'll deal with are 2,8,10, and 16. Even base 8 has fallen out of favor, but i guess it's worth working with. If you're doing this by hand, and you're moving between 2,8, and 16 there are some "tricks". Every octet is 3 bits, every hexit is 4 bits. Knowing this you can do conversions from either of these bases to base 2 or back again pretty quickly and easily with grouping. Note that between 2,8, and 16 you can exactly represent anything from one of these bases in one of the others. This isn't so with base 10, so we end up making approximations because converting from one of the other bases to base 10 can give us an irrational number, and some decimal numbers with a fractional part cannot be represented in binary at all, so they have to be estimated.

    -Lee
     
  6. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009

Share This Page