Code archives/Algorithms/UnHex/reHex

This code has been declared by its author to be Public Domain code.

Download source code

UnHex/reHex by Andres2006
UnHex%("0F") ; Returns 15
ReHex(255) ; returns "FF"
Function ReHex$(value%)
	Return Right$(Hex(value%), 2)
End Function

Function UnHex%(txt$)
	txt$ = Upper(txt$)
	
	Local a = Asc(Mid$(txt$, 1, 1)) - 48
	If a > 10 Then a = a - 7
	Local b = Asc(Mid$(txt$, 2, 1)) - 48
	If b > 10 Then b = b - 7
	
	Return a * 16 + b
End Function

Comments

None.

Code Archives Forum