Negative numbers


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    RUBiksCUbe's Avatar
    RUBiksCUbe Guest

    Default Negative numbers

    I'm trying to set a variable to the negative of another variable by saying:
    remaining = -rows
    Where rows has already been set to 8, but remaining seems to end up being set to 0 instead of -8.

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    "...Keep in mind that all of the math and comparisons in PBP are unsigned."

    Will you use that negative number in a math operation or is it just for a representation on LCD or sending via a serial comm. etc?
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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


    Did you find this post helpful? Yes | No

    Default

    Unless it has something to do with a previous version of PBP, can't say.
    But this simple program comes up with 248 (-8). PBP 2.46
    Code:
     @  __CONFIG    _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H
    define OSC 20
    clear
    
    remaining var byte
    rows      var byte
    
    rows = 8
    remaining = -rows
    
    stop
    Something you might try is ...

    remaining = 0 - rows
    DT

  4. #4
    RUBiksCUbe's Avatar
    RUBiksCUbe Guest


    Did you find this post helpful? Yes | No

    Default

    I'm not using it for any math operations, just to control the start of a for loop.
    Code:
    for i = remaining toremaining + (rows - 1)
        if i < 0 then
            messageScroll[writePos] = $0
        endif
        if i >= 0 and i < messagelength then
            messageScroll[writePos] = message[i]
        endif
        if i >= messageLength then
            messageScroll[writepos] = $0
        endif
        writePos = writePos + 1
    next i
    for some reason when remaining is negative this part "crashes"
    Last edited by RUBiksCUbe; - 24th September 2006 at 20:24.

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi RUBiksCUbe,

    Where do you get this "Remaining" variable into negative? Are you setting it to "negative" somewhere before this loop as you stated in the example above?


    Also, here I made the same code of yours in a different look.
    It seems you only need the negative value for " messageScroll[writePos] = $0 "


    Code:
    
    for i = remaining to remaining + (rows - 1)
    
        if i < 0 then 
            messageScroll[writePos] = $0
    
        else
    
            if i < messagelength then 
               messageScroll[writePos] = message[i]
            else
               messageScroll[writepos] = $0
            endif
    
        endif
    
        writePos = writePos + 1
    
    
    next i


    Also, are you setting other variables to an initial value at the beginning?






    --------------------------
    Last edited by sayzer; - 25th September 2006 at 10:54.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    RUBiksCUbe's Avatar
    RUBiksCUbe Guest


    Did you find this post helpful? Yes | No

    Default

    At the very beginning I have

    Code:
    rows = 8
    remaining = (0 - rows)

Similar Threads

  1. Working with 3 byte numbers
    By Josuetas in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th July 2007, 22:59
  2. Splitting numbers and recombining them(EEPROM Error)
    By selbstdual in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd June 2007, 06:40
  3. Returning whole numbers for DS1820?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th February 2007, 12:15
  4. Reading (ADC) negative current
    By sougata in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 21st November 2006, 17:38
  5. Can PBP understand negative numbers?
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th June 2005, 00:23

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