CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2006
    Posts
    127

    [RESOLVED] hex binary etc

    Hello, I am puzzled as to how to convert a hex number to a binary and then to a decimal number. According to my book it should be a very simple algorithm, and yet I am puzzled. Can anybody give me a hint ?
    I know how to convert between hex/decimal/binary numbers but I don't know how to do that in assembler. I am using NASM.
    Any help is appreciated.

  2. #2
    Join Date
    Nov 2004
    Posts
    34

    Re: hex binary etc

    I'm assuming you want to convert them to ascii. Binary is fairly simple.

    Just load the number into a register shift left, the carry flag will tell you if the next digit is a zero or a one, store it into your buffer, repeat for all the bits in the register.

    Converting to decimal requires a bit of knowledge of the ASCII table.
    Work on it one byte at a time. Each nibble in the byte represents one hex digit which still needs to be converted into a decimal digit.
    -isolate the high order nibble
    -OR it with char '0'
    -if the result is greater than char '9', then add 7 (not char '7'!) to the result.
    -append this into your buffer.
    -repeat with low order nibble.

  3. #3
    Join Date
    Feb 2006
    Posts
    127

    Re: hex binary etc

    Thank you for your help. It works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured