two’s complement


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default two’s complement

    I have searched the manual and this forum for the two’s complement command. I guess I can't find it or there is none.

    So will this do it?
    Code:
    CHKSUM = (CHKSUM REV7)+1
    Or is there a way I have not found?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default Re: two’s complement

    There are a couple ways to work with 2's compliment numbers.
    "2's compliment" is simply a way to store positive and negative numbers.

    You can can change a number to a positive value when it's either positive or negative using the ABS (Absolute Value) function.

    PosValue = ABS MyValue

    Or, a value can be inverted ... made positive if it's negative, or negative if it's positive using the negative sign.

    InvValue = -(MyValue)

    That is the same as complimenting the bits and adding 1.
    Which can also be done with the bitwise NOT operator (+1).

    InvValue = ~(MyValue) + 1
    DT

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: two’s complement

    Ok, thanks Darrel, I will use the last 1. It just looks cool!
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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