shifting negative long vars


Closed Thread
Results 1 to 5 of 5

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    ive solved the problem with this code to divide x by 256:

    Code:
    IF x.31 then                 ' if negative:
        x=~x+1                   ' convert from 2s complement
        x=x>>8                   ' shift
        x=~(x-1)                 ' convert back to 2s complement
        x.31=1                   ' set signed bit (negative)
        if x=$80000000 then x=0  ' negative 0 is 0
    ELSE                         ' else (positive):
        x=x>>8                   ' shift
    ENDIF
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

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


    Did you find this post helpful? Yes | No

    Default

    after some playing i found a simpler way:

    Code:
    negative=x.31           ' Save the sign bit
    x=(ABS x)>>8            ' Shift the absolute value
    IF negative THEN x=0-x  ' Make negative again
    Last edited by Kamikaze47; - 26th April 2010 at 18:55.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

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