Hatte mir dafür mal 'ne kleine Funktion geschrieben (Allerdings linear für eine größere Datenmenge, daher müsste das Ergebnis bei einem DWORD gebyteswapped werden):
Code:
push 8
push _buf
push _n
call hextol
mov eax,[_n]
bswap eax
_buf db '12AB34CD',0
_n dd ?
hextol:
push esi edi
mov edi,[esp+8+4]
mov esi,[esp+8+8]
mov edx,[esp+8+12]
shr edx,2
jnc .loop
mov ax,[esi]
mov cx,[esi]
sub ax,'00'
sub cx,'00'
and ax,1010h
shr ax,4
imul ax,7
sub cx,ax
and cx,0F0Fh
shl cl,4
or cl,ch
mov [edi],cl
add esi,2
inc edi
test edx,edx
je .fin
.loop:
mov eax,[esi]
mov ecx,[esi]
sub eax,'0000'
sub ecx,'0000'
and eax,10101010h
shr eax,4
imul eax,7
sub ecx,eax
and ecx,0F0F0F0Fh
shl cl,4
or cl,ch
mov al,cl
shr ecx,16
shl cl,4
or cl,ch
mov ah,cl
mov [edi],ax
add esi,4
add edi,2
dec edx
jnz .loop
.fin:
pop edi esi
retn 0Ch
Du könntest aber auch einfach wie Medix bereits meinte atoi oder auch sscanf verwenden:
Code:
char buf[] = "0x12AB";
int n;
sscanf(buf, "0x%X", &n);
printf("n=%X atoi(n)=%X", n, atoi(n));