473,398 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

A97 OCT & HEX FN's - is there a similar DEC Fn or something to go to BASE10?

MLH
Seeking base 10 conversion for OCT
and HEX numbers. I see A97 as OCT & HEX
Fn's to convert decimal numbers to those
2 BASEs. What about the other way around?
Nov 13 '05 #1
4 1368
MLH
FOUND IT.

CLng("&h" & [HexCode])
Nov 13 '05 #2
MLH, this one's easy.
Octal values are prepended with an ampersand (&), so 15 would be &17.
Hex values are prepended with an ampersand H, so 31 would be &H1F.

The Val function is smart enough to recognize the special prepended
characters.

intDecimalNumber = Val(&17)

if the Oct function was used, it returned a string, so to convert it
back you would use the syntax:

intDecimalNumber = Val("&" + strOctal)

for hex numbers the syntax would be:

intDecimalNumber = Val("&H" + strHex)

Cut and paste the following code for an example:

Private Sub ConvertOct()
Dim strOctal As String
Dim intDecimal As Integer
Dim intNewDecimal As Integer
intDecimal = InputBox("Enter any decimal value and press enter",
"GETTING A VALUE")
strOctal = Oct(intDecimal)
MsgBox "The octal value is " & strOctal
intNewDecimal = Val("&" + strOctal)
MsgBox "The octal value converted back to decimal is " &
str(intNewDecimal)
End Sub

Taking it one step further, you can write a function to accept an octal
and return a decimal:

Public Function OctalToDecimal(strOctal As String) As Integer
OctalToDecimal = Val("&" + strOctal)
End Function

Hope this helps.

Neil

Nov 13 '05 #3
MLH
Thanks for the very thorough reply and all your suggestions.
There certainly is more than one way to skin a cat.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

MLH, this one's easy.
Octal values are prepended with an ampersand (&), so 15 would be &17.
Hex values are prepended with an ampersand H, so 31 would be &H1F.

The Val function is smart enough to recognize the special prepended
characters.

intDecimalNumber = Val(&17)

if the Oct function was used, it returned a string, so to convert it
back you would use the syntax:

intDecimalNumber = Val("&" + strOctal)

for hex numbers the syntax would be:

intDecimalNumber = Val("&H" + strHex)

Cut and paste the following code for an example:

Private Sub ConvertOct()
Dim strOctal As String
Dim intDecimal As Integer
Dim intNewDecimal As Integer
intDecimal = InputBox("Enter any decimal value and press enter",
"GETTING A VALUE")
strOctal = Oct(intDecimal)
MsgBox "The octal value is " & strOctal
intNewDecimal = Val("&" + strOctal)
MsgBox "The octal value converted back to decimal is " &
str(intNewDecimal)
End Sub

Taking it one step further, you can write a function to accept an octal
and return a decimal:

Public Function OctalToDecimal(strOctal As String) As Integer
OctalToDecimal = Val("&" + strOctal)
End Function

Hope this helps.

Neil


Nov 13 '05 #4
Thanks from me as well. That's an excellent solution.

James A. Fortune

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: A.B., Khalid | last post by:
I wonder if someone can explain what is wrong here. I am pickling a list of dictionaries (see code attached) and unpickling it back using the HIGHEST_PROTOCOL of pickle and cPickle. I am getting an...
1
by: Matt Garman | last post by:
Is there a generally accepted means of generating reports in C and/or C++? In particular, I have an application with many parameterized text strings that get displayed to a user. These could be...
4
by: Luklrc | last post by:
Hi, I'm having to create a querysting with javascript. My problem is that javscript turns the "&" characher into "&" when it gets used as a querystring in the url EG: ...
15
by: rwf_20 | last post by:
I just wanted to throw this up here in case anyone smarter than me has a suggestion/workaround: Problem: I have a classic producer/consumer system which accepts 'commands' from a socket and...
28
by: Martin Jørgensen | last post by:
Hi, I have a "funny" question, which I think is pretty "healthy" to examine... This program is being investigated: - - - - - - - #include <iostream> using namespace std; #define DAYS 7
7
by: Kirt | last post by:
i have walked a directory and have written the foll xml document. one of the folder had "&" character so i replaced it by "&amp;" #------------------test1.xml <Directory> <dirname>C:\Documents and...
5
by: robert | last post by:
Turning algs for old NumPy modules into numpy code I suffer from this: Upon further processing of returns of numpy calculations, lots of data in an apps object tree will become elementary numpy...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
0
by: Taxman | last post by:
Windows XP, MS Office Excel 2003 If the tasks, I’m trying accomplish have been addressed previously (separately or in combination). Please, provide the links or keyword search to find them. I’ve...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.