How to convert decimal to any base

Discussion in 'Questions (Windows Mobile)' started by johnpc, Jun 4, 2009.

How can a decimal input be converted to Hex, Octal,Binary or any Base.
I can do this in VB6 but can't seen to in BASIC4PPC. Problem lies in
trying to use the String Mid Function as given below.

Sub btnCalc_Click
Dim HexString
Dim DecValue

HexString = ""
DecValue = txtInput.Text

Do While DecValue > 0
'Get least significant character
HexString = mid("0123456789ABCDEF",Mod(DecValue,16 )+ 1,1) + HexString
'Remove least significant character

DecValue = Int(DecValue/16)
Loop

If len(HexString) < 2 Then
Decimal2Hex = "&H" + Right("00" + HexString,2)
Else
Decimal2Hex = "&H" + HexString
End If

txtOutput.Text = Decimal2Hex

End Sub
Any Help will be appreciated

Hello johnpc,

a conversion between decimal, hexadecimal and binary values can easily be done with the bitwise.dll.

specci48

Hi,

There is a Binary, Decimal, Hexadecimal conversion
program example listed in the "Share Your Creations"
section of the B4PPC Forums.

This program uses the Bitwise.dll.

Check out the postings by PDABLUE.

`...HexString = [COLOR="Red"]mid[/COLOR]("0123456789ABCDEF",Mod(DecValue,16 )+ 1,1) + HexStringIf [COLOR="Red"]len[/COLOR](HexString) < 2 ThenDecimal2Hex = "&H" + [COLOR="Red"]Right[/COLOR]("00" + HexString,2)`