code conversion


Closed Thread
Results 1 to 4 of 4

Thread: code conversion

Hybrid View

  1. #1
    Join Date
    Oct 2008
    Posts
    14


    Did you find this post helpful? Yes | No

    Default

    Hi Jerson

    thanks for the reply

    the 1st point i have removed the lines for that and forgot to put them back in (i removed them to make it a bit simpler to follow).

    the second point is i think where the problem with the conversion is occurring.
    i get compile errors if i try to force the variables to hex.

    dj.lambert

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    973


    Did you find this post helpful? Yes | No

    Default

    Hi Dj

    You do not need to force the values to Hex, instead you need to convert the HEX values to word. Since PBP does not support a function like VB does, you need to build this code. A simple routine to convert a hex character to byte would be

    Code:
    ' expects a HEX character with capitalized A-F values
    Hex2Bin:
        Hexchar = Hexchar - "0"          ' remove the value of ascii 0 (30H)
        if Hexchar > 9 then  Hexchar = Hexchar - 7   ' convert A-F to 0a-0Fh
        return
    Now, you would do this 4 times once for each nibble in the word you are converting and get your Hex word like this

    Code:
       WordVal = 0                              ' start with a val of 0
       read a hex character to HexChar
      gosub Hex2Bin
      WordVal = WordVal * 16 + HexChar
       read a hex character to HexChar
      gosub Hex2Bin
      WordVal = WordVal * 16 + HexChar
       read a hex character to HexChar
      gosub Hex2Bin
      WordVal = WordVal * 16 + HexChar
       read a hex character to HexChar
      gosub Hex2Bin
      WordVal = WordVal * 16 + HexChar
    Now, WordVal would contain the 16 bit representation of the 4 character Hex String

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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