Menu

GCB 2's complement subtraction

jeff
2021-03-18
2021-03-18
  • jeff

    jeff - 2021-03-18

    Variable Type "INTEGER" try 1-4
    Dim bb as integer
    bb=1-4
    Print Str(bb)
    END
    This prints 65533
    How can I get a Print of -3. I thought that the Integer type would recognize a MSB of 1 and report -3

     
  • William Roth

    William Roth - 2021-03-18

    This code works as expected and returns -3

     #chip 18f27Q43, 16
     #CONFIG MCLRE=ON, LVP = ON
     #option Explicit
    
     #startup InitPPS, 85
     #define PPSToolPart 18f47q43
    
     #Define USART_BAUD_RATE 19200
     #DEFINE USART_TX_BLOCKING
      Wait 500 ms
    
    Dim Testvar as integer
         TestVar = (1-4)
    HSerprint "TestVar = "
    HSerprint TestVar
    
    End
    Sub InitPPS
        'Module: UART1
         RC6PPS = 0x0020    'TX1 > RC6
    End Sub
    

    Perhaps you should not be using "STR" with Print

    Simply use : Print BB

     

    Last edit: William Roth 2021-03-18
  • mmotte

    mmotte - 2021-03-18

    Try:
    Print bb

    Print is overloaded and will print the type you send it.

     
  • Anobium

    Anobium - 2021-03-18

    Use Str32()

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.