Octal conversion

1. Senior Member
Join Date
Dec 1969
Posts
2,050

## Octal conversion

I am working on an algorithm that uses the Oct() function of vbscript. I need to convert the returned value from Oct(n) back into a base10 value. Is there a built in function that does this so I don&#039;t waste my time?<BR>thx

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

## Did you read the docs?

On the OCT() function?<BR><BR>http://msdn.microsoft.com/library/en-us/script56/html/vsfctoct.asp<BR><BR>The answer is right there.<BR><BR>If you want the answer, I&#039;ll give it to you, but don&#039;t you want to try it, first?<BR><BR>HINT: Use CLNG.<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
2,050

## Whoops

I was calculating Oct(x) + Oct(y) + Oct(z) and writing out oct(x) + oct(y) - oct(z). No wonder things didn&#039;t match up. duh... Was wondering why Cint wasn&#039;t working. When changing to Clng as per your suggestion, I noticed the error. lol!<BR>

4. Senior Member
Join Date
Dec 1969
Posts
11,334

## What?

Unless VBS has something like 0xWhatever or 08whatever, using clng() won&#039;t do anything...<BR>MyOct = Oct(459) &#039; Returns 713.<BR>MyOct is really "713"<BR><BR>myDec = Clng(myoct) &#039;nope<BR><BR>I can&#039;t remember if Oct or Hex has a letter in front of it in VBS, but if it did, then sure, you could use it. I didn&#039;t see it in that link, however.

5. Senior Member
Join Date
Dec 1969
Posts
11,334

## LOL

I guess it was there...<BR><BR>&#062;can represent octal numbers directly by preceding numbers in the proper range with &O. <BR><BR>I guess for Hex it&#039;s &H ?

6. Senior Member
Join Date
Dec 1969
Posts
2,050

So, there is no builtin vbscript function to convert back?

7. Senior Member
Join Date
Dec 1969
Posts
2,050

## oh crap

now i&#039;m confused.. uh, how does this help me again? :?)

8. Senior Member
Join Date
Dec 1969
Posts
11,334

## No, there is

Your post confused me why you got the answer, but I reread Bill&#039;s link and it was there. If you did<BR><BR>MyDec = CLng("&0" & ThatOctalNum)<BR><BR>I wasn&#039;t sure if VBS had the "&0"

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

## UN-what...

Yep, you got it.<BR><BR> MyOct = Oct(459) &#039; returns the *string* "713"<BR> MyDec = CLNG( "&O" & MyOct )<BR><BR>

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

## YES YES NOD NOD <eo-nod>

.

#### Posting Permissions

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