Hex digit verification


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    Hi,
    It looks to me like you have a two digit BCD value packed into one byte, is that correct?

    I'm sure there are better and more clever ways of doing it but this seems to do what I think it is you're asking about:
    Code:
    If (CheckPanelDigit & 15) < 10 AND (CheckPanelDigit & 240) >> 4 < 10 then
    '...more code here
    Try it out and see if it does what you want.

    /Henrik.

  2. #2
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Thanks Henrick,

    Sure is prettier than my code . As far as the BCD in a byte, yep, pretty much it. It can be any Hex digit in there. So, I just need to make sure each nibble in the byte is a number, not a letter. I'll give your code a shot in a bit. I'll have to intentionally read from the wrong address to make a go of it. On another quick note, would you have a quick and easy, down and dirty way to "flip" the 2 hex characters around? ie: HEX59 becomes HEX95. One of the panels I am working on stores its codes "backwards". Sneaky 'lil buggers. I need to flip 'em so I can display them on the lcd. I've got a routine working now, the low nibble - high nibble way, but just wondering if there was a better way?

    Thanks again,
    Chris

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    Hi Chris,
    You actually posted while I was typing my reply - I didn't see your own response.

    Anyway, if you can afford two new bytes, lets call them Ones and Tens then you could do something like this instead (it produces slightly smaller code:
    Code:
    Ones VAR BYTE
    Tens VAR BYTE
     
    Ones = CheckPanelDigit & 15
    Tens = (CheckPanelDigit & 240) >> 4
     
    If Ones < 10 AND Tens < 10 then
    '....more code here
    This will then allow you to do something like:
    Code:
    SwappedValue VAR BYTE
    SwappedValue = Ones << 4 + Tens
    Which swappes the order of the high and low nibble in the byte.

    /Henrik.

  4. #4
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Very cool Henrick, thanks. When I get a second to try that code, I will. I'll report back asap.

    Thanks again,
    Chris

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