WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Sponsors
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
Personal menu
Welcome Guest
User:
Pass:
Register!
Resend Validation Email
 
Forum
 

converting a string to hexadecimal

Wessol
Quote Post


Member
**

Group: Members
Posts: 32
Member No.: 51593
Joined: 16-May 12


he folks im back again with question.

i want to convert a string to hex, but dont know how. i googled and found some things, but its to hard for me to understand the code.

i need a function that converts a string to hex in a range of 0..9 & A..Z.

does anybody have a idea to help me?

like this: 0 > 30 , R > 52
PMEmail Poster
Top
ragdog
Quote Post


Extremely Active Member
******

Group: Moderators
Posts: 873
Member No.: 5019
Joined: 13-May 07


Hi

This code convert a String "Encodeme"to hex "456E636F64656D65"

CODE


include \masm32\include\masm32rt.inc

; added a PROTOtype near the beginning of the source so we can use INVOKE

HexEncode PROTO :dword,:dword,:dword

.data
HexWord db "Encodeme"      ; we pass the length, so a null terminator is not required

.data?
hOut db 260 dup (?)

.code
start:

invoke HexEncode,offset HexWord,sizeof HexWord,offset hOut

invoke MessageBox,0,addr hOut ,0,MB_OK
invoke ExitProcess,0

HexEncode proc uses edi esi ebx pBuff:dword,dwLen:dword,pOutBuff:dword
;---------------------------------------
 mov    ebx, dwLen
 mov    edi, pOutBuff
 test    ebx, ebx
 mov    esi, pBuff
 jz      @F
 .repeat
   movzx  eax, byte ptr [esi]
   mov    ecx, eax
   add    edi, 2
   shr    ecx, 4
   and    eax, 1111b
   and    ecx, 1111b
   cmp    eax, 10
   sbb    edx, edx
   adc    eax, 0
   lea    eax, [eax+edx*8+'7']
   cmp    ecx, 10
   sbb    edx, edx
   adc    ecx, 0
   shl    eax, 8
   lea    ecx, [ecx+edx*8+'7']
   or      eax, ecx
   inc    esi
   mov    [edi-2], ax
   dec    ebx
 .until ZERO?
@@: mov    eax, edi
 mov    byte ptr [edi], 0
 sub    eax, pOutBuff
 ret
;---------------------------------------
HexEncode endp
end start


Greets,
PMUsers Website
Top
Wessol
Quote Post


Member
**

Group: Members
Posts: 32
Member No.: 51593
Joined: 16-May 12


nice code and easy to understand thank you so much!
i love you biggrin.gif
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian
Google