I have these here stored in my collection:
Code:
Procedure DecByteSequenceToHexByteString(*seq.ascii,length.l,*HexString.ascii)
;This function converts a byte sequence stored in a given base address of sequential memory to a Hex string (.s):
For t.l=1 To length.l
*HexString\a=Asc(Hex((*seq\a>>4)&$0F)); <-HighNibble
*HexString+1
*HexString\a=Asc(Hex(*seq\a&$0F)); <-LowNibble
*HexString+1
*seq+1
Next
*HexString\a=0
EndProcedure
Procedure.b HexByteStringToDecByteSequence(HexString.s,*seq.ascii)
;This function converts a given Hex string (.s) to a byte sequence stored in a given base address of sequential memory:
Protected c.a,Nibbles.l=Len(HexString.s),t.l
If Nibbles.l&1:HexString.s="0"+HexString.s:Nibbles.l+1:EndIf
For t.l=1 To Nibbles.l
c.a=Asc(LCase(Mid(HexString.s,t.l,1)))
If c<'0' Or c>'f' Or (c>'9' And c<'a')
ProcedureReturn 0
EndIf
If c>'9':c=(c&$5F)-$07:EndIf
c-'0'
If t.l&1
*seq\a=c<<4
Else
*seq\a|c
*seq+1
EndIf
Next
ProcedureReturn 1
EndProcedure
;Test it:
*d.byte=AllocateMemory(22)
HexByteStringToDecByteSequence("e153a9a6449b16d0bd950fe6b9e762b43cdabbe4ec0193505822854c109029e9",*d.byte)
For t=1 To 22
Debug Hex(PeekB(*d.byte+t-1)&$FF)
Next
st.s=Space(22*2)
DecByteSequenceToHexByteString(*d.byte,22,@st.s)
Debug st.s
And in i386 assembler this one:
Code:
Procedure StringToHex(cPuntero.l,cCantidad.l,cBuffer.l)
;This function converts String to hex sequence:
!pushad
!mov esi,dword[p.v_cPuntero+32]
!mov edi,dword[p.v_cBuffer+32]
!.bucle:
!cmp dword[p.v_cCantidad+32],0
!je .salir
!xor edx,edx
!movzx eax,byte[esi]
!mov ebx,16
!div ebx
!mov bl, byte[numeros+eax]
!mov byte[edi],bl
!mov bl, byte[numeros+edx]
!mov byte[edi+1],bl
!add edi,2
!inc esi
!dec dword[p.v_cCantidad+32]
!jmp .bucle
!.salir:
!popad
ProcedureReturn
!numeros db '0123456789ABCDEF',0
EndProcedure
;Test it:
ff$="* PureBasic *"
vv$=Space(Len(ff$)*2)
StringToHex(@ff$,Len(ff$),@vv$)
Debug vv$