ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How to get different base systems so letters will show up like hex system tia sal2 (https://www.excelbanter.com/excel-discussion-misc-queries/120548-how-get-different-base-systems-so-letters-will-show-up-like-hex-system-tia-sal2.html)

[email protected]

How to get different base systems so letters will show up like hex system tia sal2
 

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


Leo Heuser

How to get different base systems so letters will show up like hex system tia sal2
 
" 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.




All times are GMT +1. The time now is 11:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com