| Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free! |
visual basic number conversion
|
Original Message
|
Name: phyre
Date: July 8, 2003 at 12:40:56 Pacific
Subject: visual basic number conversionOS: Windows XP ProCPU/Ram: 2.4 ghz / 384 mb |
Comment: If I convert a number into octal, how do I convert it back? The same for hexagonal. Thanks.
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: Duarte
Date: July 8, 2003 at 16:09:10 Pacific
|
Reply: (edit)Here's an example of a conversion There are many many different ways to this type of conversions... Dim Hexz as string Dim Number as long Number = 12345 Hexz = Hex(Number) 'Hex() returns string MsgBox Hexz Number = Val("&H" & Hexz) 'Get the Long 'decimal value by putting "&H" before the hex 'value, and let the Val() function 'automatically convert it. 'MsgBox Number 'you will see that it is 12345 Actually you could also store the Hex value in a long type var, using CLng()
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: Burbble
Date: July 12, 2003 at 09:25:19 Pacific
|
Reply: (edit)Here's a formula you can use to convert to Base-10: For each digit, starting with the one farthest on the right, add the sum of the digit times the original base to the power of the position (the first position is 0, the next is 1, etc.) For example: Binary 10100100 would be: 0*2^0 + 0*2^1 + 1*2^2 + 0*2^3 + 0*2^4 + 1*2^5 + 0*2^6 + 1*2^7 = Base 10 equivilent = 164 It's not a very complicated formula to execute with a For/Next loop. -Burbble
Report Offensive Follow Up For Removal
|

Post Locked
This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
Go to Programming Forum Home