Bit conversion


Closed Thread
Results 1 to 12 of 12

Thread: Bit conversion

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default

    PBP do not take signed intergers

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default

    Lerameur,

    Multiplications with negative numbers works but if you need division you need to do a little "manual" work:
    Code:
    Sign VAR Word       'This will hold the sign of our value.
    Left VAR Word
    Right VAR Word
    Temp VAR Word
    
    Left = 100
    Right = 200
    
    Temp = Left - Right     'Temp is now -100 (or 65436)
    
    If Temp.15 = 1 then    'Highest bit set means value is negative
       Sign = -1
    Else
       Sign = 1
    Endif
    
    'We cant divide a negative number so we have to use the ABS operator.
    Temp = ABS(Temp) / 2    'Temp is now 50 (positve)
    
    Temp = Temp * Sign       'Re-apply sign, Temp is now -50 (or 65486)
    /Henrik Olsson.

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


    Did you find this post helpful? Yes | No

    Default

    hi Henrik,

    I am not sure how lerameur will implement this information into his problem.


    ---------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Sorry...

    Hi Sayzer,
    He said PBP don't 'take' signed integers and I showed him a way to get around it. I guess I didn't understand the problem, still don't then....

    Sorry if I made more confusing.

    /Henrik Olsson.

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


    Did you find this post helpful? Yes | No

    Default

    NP Henrik,

    His problem is with floating point issue that PBP does not support.

    As you said he still needs to do some manual work.



    He will take care of his problem with a few more code lines.
    -----------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 08:55
  2. Doubt with interrupt on change
    By lugo.p in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th March 2010, 16:22
  3. Sleep Mode
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th March 2008, 11:31
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 01:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 02:07

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