02-18-2006, 08:05 AM
Code:
Function bintohex( d As String ) As String
Dim As String ret, foo, tmp
Dim As Integer i, j
foo = d
Dim As zString Ptr hex_chars( 15 )=> _
{ _
@"0", _
@"1", _
@"2", _
@"3", _
@"4", _
@"5", _
@"6", _
@"7", _
@"8", _
@"9", _
@"A", _
@"B", _
@"C", _
@"D", _
@"E", _
@"F" _
}
If ( Len( foo ) And 2 ) <> 0 Then
foo = String( ( Len( foo ) And 2 ), Asc( "0" ) ) + foo
End If
For i = 0 To ( Len( foo ) \ 4 ) - 1
For j = 0 To 3
tmp += Chr( *cptr( Byte Ptr, @foo[( i * 4 ) + j] ) )
Next
tmp = "&B" & tmp
ret += *hex_chars( Val( tmp ) )
tmp = ""
Next
Return ret
End Function
? bintohex( "1010" &"1111" &"1110" &"0010" &"0010" & "0111" )
Sleep
freebasic only, they don't teach you that in school!!