BASIC math question: Base 8 to base 10

# Thread: BASIC math question: Base 8 to base 10

1. Junior Member
Join Date
Dec 1969
Posts
11

## BASIC math question: Base 8 to base 10

How can I change a number from base 8 to base 10?

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Is this homework? (Must be!)

How about showing what you have done so far?<BR><BR>

3. Junior Member
Join Date
Dec 1969
Posts
11

## RE: Is this homework? (Must be!)

No it is not a homework. It is just for personal knowledge.<BR><BR>For your info, I have been working with ASP for 2.5 years, and I just realized I have been too much of basic stuff. Hence I am trying to learn on my own a little more to be more valiable to my company and to my professional career.

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Okay, I'll believe you...

&#060;%<BR>octal = "713301" &#039; get an octal number from someplace<BR><BR>decimal = 0<BR>For i = 1 To Len(octal)<BR> decimal = 8 * decimal + ( Asc(Mid(octal,i,1)) - Asc("0") )<BR>Next<BR><BR>Response.Write decimal & " is the decimal equivalent of octal " & octal<BR>%&#062;<BR><BR>HOW IT WORKS:<BR><BR>Remember, each digit in an octal number represents that digit times a power of 8. And the further left you go in the octal digits, the higher the power of 8.<BR><BR>If there are 3 digits, say "713", then the number is <BR> 7 * 64 + 1 * 8 + 3<BR>but then you realize that 64 is just 8*8 and you can rearrange that to:<BR> ( ( (7 * 8) + 1 ) * 8 ) + 3<BR>and now you can see where the program comes from:<BR><BR> decimal = 0<BR> decimal = (0 * 8) + 7 --&#062;&#062; 7<BR> decimal = (7 * 8) + 1 --&#062;&#062; 57<BR> decimal = (57 * 8) + 3 -- which is same as ( (7 * 8) + 1) * 8 + 3<BR><BR>See?<BR><BR>

5. Junior Member
Join Date
Dec 1969
Posts
11

## Thanks

****. I thought there were a command for that. No wonder why you throught it was a school assignement.<BR><BR>Thanks a lot for your help.

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## Oh, duh! It *is* built in!

STUPID ME!<BR><BR>Same way you do it with HEX numbers!<BR><BR>&#060;%<BR>octal = "1731002"<BR><BR>decimal = CLNG( "&O" & octal )<BR>%&#062;<BR><BR>Presto.<BR><BR>And of course there is the OCT( ) function to go the other way.<BR><BR>Just like with hex numbers:<BR><BR>&#060;%<BR>hexnum = "A3F9B"<BR><BR>decimal = CLNG( "&H" & hexnum )<BR>%&#062;<BR><BR>and the HEX( ) function to go the other way. <BR><BR>DOH! Thanks for waking me up!<BR><BR>

#### Posting Permissions

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