How do I convert a string representing a signed hex int into its signed int Doubleword number in 80x86?

后端 未结 2 625
日久生厌
日久生厌 2021-01-28 02:46

So I am taking an assembly language course and I am stuck on this problem from the book: Using the windows 32 console (so I have an io.h to use), I am supposed to t

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-28 02:54

    If you need to convert a character (for simplicity, say, in upper case) representing a hex digit into the value of that digit you need to do this:

    IF char >= 'A'
      value = char - 'A' + 10
    ELSE
      value = char - '0'
    ENDIF
    

    If you need to do the reverse, you do the reverse:

    IF value >= 10
      char = value - 10 + 'A'
    ELSE
      char = value + '0'
    ENDIF
    

    Here you exploit the fact that the ASCII characters 0 through 9 have consecutive ASCII codes and so do the ASCII characters A through F.

提交回复
热议问题