negatives


Closed Thread
Results 1 to 7 of 7

Thread: negatives

  1. #1
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429

    Default negatives

    If I subtract 1 from a variable that currently has a value of 0 what will the result be? 0? 255? or something else?

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    if it's a BYTE... yes it will be 255.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    thanks mister_e

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Depends on how you want to look at it.
    It can also be -1
    Code:
    X  VAR BYTE
    
    X = 0
    X = X - 1
    
    LCDOUT SDEC X
    Displays -1 on LCD
    <br>
    DT

  5. #5
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Post Copy/Paste from the manual

    If any are preceded by an S (for signed), the output will be sent
    preceded by a “-“ if the high order bit of the data is set. This allows the
    transmission of negative numbers. Keep in mind that all of the math
    and comparisons in PBP are unsigned. However, unsigned math can
    yield signed results. For example, take the case of B0 = 9 - 10.
    The result of DEC B0 would be “255". Sending SDEC B0 would give “-
    1" since the high order bit is sent. So with a little trickery, the unsigned
    math of PBP can yield signed results.
    Regards

    Sougata

  6. #6
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default I never knew that

    Thanks Darrel. This second post is because I have always skipped that portion of the manual and done it in hard way. Thanks again.
    Regards

    Sougata

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I never knew that
    Can't say that anymore.

    Glad to help.
    <br>
    DT

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