Clamping a value to 16bits.


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521

    Default Clamping a value to 16bits.

    Hi,
    Sorry for the vague title.... Here's the scenario:

    I'm receiving a variable length string over serial, starting with a letter, continuing with any number of decimal digits and ending with a CR. I stuff the incomming characters into an array and increments a "pointer" as I fill it up.

    I need to take the value between the letter and the CR and put that into a variable, I use the "pointer" to determine how many characters I need to grab and then use something like:
    Code:
    ArrayRead RxBuffer [SKIP 1, DEC5 myValue]   'Skip the letter, then grap 5 digits.
    No problem so far. But, since myValue is a word I need to make sure that I don't overflow it and I'm trying to come up with a solution to do that. If I receive more than 5 digits it's a done deal but if I receive 5 digits I need to know if those digits represents more than what can be stored in a word.

    Anyone got a slick way of doing it?

    Thanks!
    /Henrik.

  2. #2
    Join Date
    Nov 2008
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    split your buffer into two words variables using skip, then do your test, e.g 90500 var1=905 var 2=00
    all the best
    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    Sorry for the vague title.... Here's the scenario:

    I'm receiving a variable length string over serial, starting with a letter, continuing with any number of decimal digits and ending with a CR. I stuff the incomming characters into an array and increments a "pointer" as I fill it up.

    I need to take the value between the letter and the CR and put that into a variable, I use the "pointer" to determine how many characters I need to grab and then use something like:
    Code:
    ArrayRead RxBuffer [SKIP 1, DEC5 myValue]   'Skip the letter, then grap 5 digits.
    No problem so far. But, since myValue is a word I need to make sure that I don't overflow it and I'm trying to come up with a solution to do that. If I receive more than 5 digits it's a done deal but if I receive 5 digits I need to know if those digits represents more than what can be stored in a word.

    Anyone got a slick way of doing it?

    Thanks!
    /Henrik.

Similar Threads

  1. Combining 4 nibble to 16bits
    By isaac in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 11th November 2006, 21:40

Members who have read this thread : 1

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