flat assembler
Message board for the users of flat assembler.

 Index > Main > Hex ASCII to bin. Help me, please!
Author
Rock_maniak_forever_

Joined: 17 Feb 2010
Posts: 15
Location: Invisible country.
Rock_maniak_forever_ 06 Sep 2010, 22:26
Help me, please! I am writing a macros, which display HTML page content in window and confront with a problem. Need to know, how to translate value from hexadecimal ASCII form to binary value. I need itself algorithm, but examples are welcome.

Quote:

For example:

tag <BODY text="#1AFF58">

ASCII hex value 1AFF58 must be 026.255.088 in binary value. How can i do this translation?

Thanks!

_________________
Proletarian of all countrys, unite!
Workers of the world, unite!

Last edited by Rock_maniak_forever_ on 06 Sep 2010, 22:49; edited 1 time in total
06 Sep 2010, 22:26

Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
026.255.088

1Ah div 10d = 2 , Remainder = 6 ---> 2 6

0FFh div 10d = 19h , Remainder = 5
19h div 10d = 2 , Remainder =5
result : 2 5 5

58h div 10d = 8 , Remainder = 8
result : 8 8

_________________
I am not young enough to know everything (Oscar Wilde)-

Last edited by ouadji on 06 Sep 2010, 22:55; edited 1 time in total
06 Sep 2010, 22:41
Rock_maniak_forever_

Joined: 17 Feb 2010
Posts: 15
Location: Invisible country.
Rock_maniak_forever_ 06 Sep 2010, 22:55
026.255.088

Yes, i do misprint. Corrected. Thanks a lot for fast answer and algorithm.

_________________
Proletarian of all countrys, unite!
Workers of the world, unite!
06 Sep 2010, 22:55
edfed

Joined: 20 Feb 2006
Posts: 4325
Location: Now
edfed 07 Sep 2010, 08:38
to convert an ASCII hexadecimal number... you need to compare digits with 'A' and '9' (not 0ah and 9)

if the digit is lower or equal to '9', then, just substract '0' and add the result to the total, shifted by the power of 16 corresponding to the rank of the digit.
if the digit is greater or equal to A, just substract 'A' to the digit, etc etc...

ones you threaded all digits, you will have the result.

in html, colors are defined in hexadecimal, or in plain text (red, blue, etc...)

this function come from this topic:
http://board.flatassembler.net/topic.php?p=82651

Code:
```specialchar:
.limit equ ds:ebp+xhtml.instop
cmp al,'&'
je .special
cmp al,' '
je @f
cmp al,9
je @f
cmp al,0ah
je @f
cmp al,0dh
je @f
jmp .ok
@@:
cmp byte[edi-1],' '
clc
je @f
mov al,' '
.ok:
stc
@@:
ret
.special:
lea edx,[esi+1]
cmp byte[edx],'#'
je .num
mov ecx,34
.name:
mov ebx,[htchars+ecx*4]
or ebx,ebx
je .none?
@@:
mov ah,[ebx]
mov al,[edx]
inc ebx
inc edx
or al,al
je .none?
cmp al,ah
jne .none?
cmp al,';'
jne @b
lea esi,[edx-1]
mov al,cl
jmp .end
.none?:
lea edx,[esi+1]
inc cl
jne .name
.none:
mov al,[esi]
.end:
or al,al
jne .ok
clc
ret
.num:
xor ebx,ebx
cmp byte[edx+1],'x'
je .hex
cmp byte[edx+1],'X'
je .hex
@@:
inc edx
cmp edx,[.limit]
jge .none
movzx eax,byte[edx]
cmp al,';'
je .num?
cmp al,'0'
jl .none
cmp al,'9'
jg .none
sub al,'0'
lea ebx,[ebx*5]
lea ebx,[ebx*2+eax]
jmp @b
.hex:
inc edx
@@:
inc edx
cmp edx,[.limit]
jge .none
movzx eax,byte[edx]
cmp al,';'
je .num?
cmp al,'9'
jg .alpha?
cmp al,'0'
jl .none
sub al,'0'
shl ebx,4
jmp @b
.alpha?:
or al,20h
cmp al,'a'
jl .none
cmp al,'f'
jg .none
sub al,'a'-10
shl ebx,4
jmp @b
.num?:
or ebx,ebx
jl .none
cmp ebx,100h
jnl .none
mov al,bl
mov esi,edx
jmp .ok
htchars:
dd 0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
dd 0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
dd 0000,0000, .34,0000,0000,0000, .38,0000,0000,0000,0000,0000,0000,0000,0000,0000
dd 0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000

dd 0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
dd 0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
dd 0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000
dd 0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000

dd .128,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,.139,0000,0000,0000,0000
dd 0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,.155,.156,0000,0000,.159
dd .160,.161,.162,.163,.164,.165,.166,.167,.168,.169,.170,.171,.172,.173,.174,.175
dd .176,.177,.178,.179,.180,.181,.182,.183,.184,.185,.186,.187,.188,.189,.190,.191

dd .192,.193,.194,.195,.196,.197,.198,.199,.200,.201,.202,.203,.204,.205,.206,.207
dd .208,.209,.210,.211,.212,.213,.214,.215,.216,.217,.218,.219,.220,.221,.222,.223
dd .224,.225,.226,.227,.228,.229,.230,.231,.232,.233,.234,.235,.236,.237,.238,.239
dd .240,.241,.242,.243,.244,.245,.246,.247,.248,.249,.250,.251,.252,.253,.254,.255
.ch:
.34  db 'quot;'
.38     db 'amp;'
.128     db 'euro;'
.139    db 'lt;'
.155      db 'gt;'
.156      db 'oelig;'
.159   db 'Yuml;'
.160    db 'nbsp;'
.161    db 'iexcl;'
.162   db 'cent;'
.163    db 'pound;'
.164   db 'curren;'
.165  db 'yen;'
.166     db 'brvbar;'
.167  db 'sect;'
.168    db 'uml;'
.169     db 'copy;'
.170    db 'ordf;'
.171    db 'laquo;'
.172   db 'not;'
.173     db 'shy;'
.174     db 'reg;'
.175     db 'masr;'
.176    db 'deg;'
.177     db 'plusmn;'
.178  db 'sup2;'
.179    db 'sup3;'
.180    db 'acute;'
.181   db 'micro;'
.182   db 'para;'
.183    db 'middot;'
.184  db 'cedil;'
.185   db 'sup1;'
.186    db 'ordm;'
.187    db 'raquo;'
.188   db 'frac14;'
.189  db 'frac12;'
.190  db 'frac34;'
.191  db 'iquest;'
.192  db 'Agrave;'
.193  db 'Aacute;'
.194  db 'Acirc;'
.195   db 'Atilde;'
.196  db 'Auml;'
.197    db 'Aring;'
.198   db 'Aelig;'
.199   db 'Ccedil;'
.200  db 'Egrave;'
.201  db 'Eacute;'
.202  db 'Ecirc;'
.203   db 'Euml;'
.204    db 'Igrave;'
.205  db 'Iacute;'
.206  db 'Icirc;'
.207   db 'Iuml;'
.208    db 'eth;'
.209     db 'Ntilde;'
.210  db 'Ograve;'
.211  db 'Oacute;'
.212  db 'Ocirc;'
.213   db 'Otilde;'
.214  db 'Ouml;'
.215    db 'times;'
.216   db 'Oslash;'
.217  db 'Ugrave;'
.218  db 'Uacute;'
.219  db 'Ucirc;'
.220   db 'Uuml;'
.221    db 'Yacute;'
.222  db 'thorn;'
.223   db 'szlig;'
.224   db 'agrave;'
.225  db 'aacute;'
.226  db 'acirc;'
.227   db 'atilde;'
.228  db 'auml;'
.229    db 'aring;'
.230   db 'aelig;'
.231   db 'ccedil;'
.232  db 'egrave;'
.233  db 'eacute;'
.234  db 'ecirc;'
.235   db 'euml;'
.236    db 'igrave;'
.237  db 'iacute;'
.238  db 'icirc;'
.239   db 'iuml;'
.240    db 'eth;'
.241     db 'ntilde;'
.242  db 'ograve;'
.243  db 'oacute;'
.244  db 'ocirc;'
.245   db 'otilde;'
.246  db 'ouml;'
.247    db 'divide;'
.248  db 'oslash;'
.249  db 'ugrave;'
.250  db 'uacute;'
.251  db 'ucirc;'
.252   db 'uuml;'
.253    db 'yacute;'
.254  db 'thorn;'
.255   db 'yuml;'

```

of course, if you want to test this function, you will need to provide the evironment... that is a little complex to aboard.

it will thread an ascii string as a special char in html form.
07 Sep 2010, 08:38
Rock_maniak_forever_

Joined: 17 Feb 2010
Posts: 15
Location: Invisible country.
Rock_maniak_forever_ 08 Sep 2010, 02:07
Excellence... Excellence... Excellence... I will be try to dismantle this. Thank you for help!
08 Sep 2010, 02:07
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum