Results 1 to 5 of 5

Thread: how do I convert a octal value to a regual number?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Location
    Lindenwold, NJ, USA
    Posts
    67

    Question

    how do I convert a octal value to a regual number?
    I can do it the other way around but not that way. HELP!
    Frankie Weindel
    VB 6 Learning Edtion SP3

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Posts
    125
    what is a regual number?

  3. #3
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I think you mean decimal value
    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
    example:
    Msgbox Base2Dec(1000,8)
    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.

  4. #4
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Take in your octal number as a string, for example:
    Code:
    strOctNum = InputBox("Enter an octal number:")
    Append the string "&O" (that's the letter "O" there) to the octal number string and use that as the argument to the Val function, assigning the result of that function to an Integer (or Long):
    Code:
    intDecimalNumber = Val("&O" & strOctNum)
    Msgbox "The decimal equivalent is: " & intDecimalNumber
    "It's cold gin time again ..."

    Check out my website here.

  5. #5
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Thumbs up Neat method BruceG!








    Mark
    -------------------

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