Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 5
Default 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

  #2   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 266
Default 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.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I not show certain Letters in a range of cells in excel? Taryn McGregor Excel Worksheet Functions 2 October 4th 06 09:49 PM
How do I make letters not show up in a alpha-numeric string? gdd6936 Excel Worksheet Functions 3 June 3rd 06 09:56 PM
Cannot save external data into file excel system show not respondi Domino415 Excel Discussion (Misc queries) 0 May 31st 06 09:01 AM
how to show different photos, base on different value of a cell? Howard Hsu Excel Worksheet Functions 2 January 25th 06 06:57 PM
Reflect file path (show drive letters) in Excel 2000 Alicia Excel Discussion (Misc queries) 4 January 20th 05 06:49 PM


All times are GMT +1. The time now is 04:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"