Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]() Greetings all I now to I can convert between different base systems using the code Function baseconv(InputNum, BaseNum) Dim quotient, remainder As Single Dim answer As String quotient = InputNum ' Set quotient to number to convert. remainder = InputNum ' Set remainder to number to convert. answer = "" Do While quotient < 0 ' Loop while quotient is not zero. ' Store the remainder of the quotient divided by base number in a ' variable called remainder. remainder = quotient Mod BaseNum ' Reset quotient variable to the integer value of the quotient ' divided by base number. quotient = Int(quotient / BaseNum) ' Reset answer to contain remainder and the previous answer. answer = remainder & answer ' Convert answer variable to a number. Loop baseconv = Val(answer) End Function but how can I get letters to show up in bases like 25 or 40? Like in the Hex system. Thanks SAL2 |
#2
![]()
Posted to microsoft.public.excel,microsoft.public.excel.misc
|
|||
|
|||
![]()
" skrev i en meddelelse
... Greetings all I now to I can convert between different base systems using the code Function baseconv(InputNum, BaseNum) Dim quotient, remainder As Single Dim answer As String quotient = InputNum ' Set quotient to number to convert. remainder = InputNum ' Set remainder to number to convert. answer = "" Do While quotient < 0 ' Loop while quotient is not zero. ' Store the remainder of the quotient divided by base number in a ' variable called remainder. remainder = quotient Mod BaseNum ' Reset quotient variable to the integer value of the quotient ' divided by base number. quotient = Int(quotient / BaseNum) ' Reset answer to contain remainder and the previous answer. answer = remainder & answer ' Convert answer variable to a number. Loop baseconv = Val(answer) End Function but how can I get letters to show up in bases like 25 or 40? Like in the Hex system. Thanks SAL2 Here's one way: Function Conv(Figure As String, _ FromBase As Long, _ ToBase As Long, _ Optional NumberOfDigits As Long) As String 'Leo Heuser, October 1999, September 2006 '=conv(Figure,FromBase,ToBase,NumberOfDigits) 'Examples: =conv(1234,6,16,6) or =conv("45ff",16,2,32) 'If NumberOfDigits is set to 0, left out or set to fewer digits 'than are in the result, the result will be displayed without 'leading zeroes. 'The setup will convert a number from base 2-16 'to another base 2-16, but the string Digits can be 'expanded to Z, and thereby covering base 2 through 36 'If the line "Figure = UCase(Figure)" is deleted, it's possible 'to place lower case letters in Digits to cover base 2-62. 'Please keep the above text, if you pass on this routine. Dim Digits As String Dim ToBaseTen As Currency Dim Dummy As Variant Dim Counter As Long Dim Result As String Conv = "Input error" Digits = "0123456789ABCDEF" If ToBase Len(Digits) Then Exit Function Figure = UCase(Figure) For Counter = 1 To Len(Figure) Dummy = Mid$(Figure, Counter, 1) If InStr(Left$(Digits, FromBase), Dummy) = 0 Then Exit Function Else ToBaseTen = ToBaseTen + (InStr(Digits, Dummy) - 1) * _ (FromBase ^ (Len(Figure) - Counter)) End If Next Counter While ToBaseTen 0 Result = Mid$(Digits, ToBaseTen - Int(ToBaseTen / ToBase) * _ ToBase + 1, 1) & Result ToBaseTen = Int(ToBaseTen / ToBase) Wend If NumberOfDigits = 0 Or NumberOfDigits < Len(Result) Then Conv = Result Else Conv = Right$(String$(NumberOfDigits - Len(Result), "0") & _ Result, NumberOfDigits) End If End Function -- Best regards Leo Heuser Followup to newsgroup only please. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I not show certain Letters in a range of cells in excel? | Excel Worksheet Functions | |||
How do I make letters not show up in a alpha-numeric string? | Excel Worksheet Functions | |||
Cannot save external data into file excel system show not respondi | Excel Discussion (Misc queries) | |||
how to show different photos, base on different value of a cell? | Excel Worksheet Functions | |||
Reflect file path (show drive letters) in Excel 2000 | Excel Discussion (Misc queries) |