How to invert just a bit - complement of a bit


+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Junior Member kuhrig's Avatar
    Join Date
    Aug 2005
    Posts
    94
    Thumbs Up
    Received: 4
    Given: 0
    Total Downloaded
    4.53 GB

    0 Not allowed!

    Default How to invert just a bit - complement of a bit

    I would like to get some help how to invert just a bit. I'm using the complement sign, but it does not work.

    Example:

    dim btemp as byte

    btemp = 11

    btemp.1 = ~btemp.0

    Result:
    btemp = 11

    Does not work. Bit result of complement bit always 1.

    Now I use:
    If btemp.0 = 1 then
    clear btemp.1
    else
    set btemp.1
    endif

    Thanks.

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,239
    Thumbs Up
    Received: 75
    Given: 181
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: How to invert just a bit - complement of a bit

    How about
    btemp = %00000011
    btemp.1 = ~btemp.0
    this equals 1 after invert
    George.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    Prolific Poster RGV250's Avatar
    Join Date
    Aug 2005
    Posts
    2,342
    Thumbs Up
    Received: 29
    Given: 7
    Total Downloaded
    1.09 GB

    0 Not allowed!

    Default Re: How to invert just a bit - complement of a bit

    Hi,
    This works on the individual bits and you can simulate it in the free VSM
    Code:
    'Simulates in PIC16_ALCD_VHB.DSN board
        Include "Proton_4.Inc"
    
    ' ** Declare Variables **
        Dim Testbits  As Byte
        Dim Testbits1 As Byte
        Testbits.0 = 1
        Testbits.1 = 0
        Testbits.3 = 1      'Used so preceding 0 shows
        Testbits1.3 = 1     'Used so preceding 0 shows
        
        Dim btemp As Byte
            
        DelayMS 100
        Cls
    
    MainLoop:
        Print At 1,1,Bin Testbits     'Show initial state
        Testbits1.0 = ~Testbits.0     'Invert bit 0
        Testbits1.1 = ~Testbits.1     'Invert bit 1
        Print At 2,1,Bin Testbits1    'Show inverted states 
        
        btemp = %00001011    
        Print At 1,6,Bin btemp    'Show inverted states     
        btemp.1 = ~btemp.0      
        Print At 2,6,Bin btemp    'Show inverted states 
        GoTo MainLoop
    Last edited by RGV250; 26th June 2019 at 21:54.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,428
    Thumbs Up
    Received: 296
    Given: 142
    Total Downloaded
    1.75 GB

    0 Not allowed!

    Default Re: How to invert just a bit - complement of a bit

    I've just ran so me tests and teh inversion of bits using the complement operator is working OK.

    On an 18F device it uses the Btg mnemonic, with 14-bit core devices it uses an Xor mnemonic if both bits are the same. Otherwise, it uses a set of mnemonics to test the condition of the source bit and set or clear the destination bit.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,428
    Thumbs Up
    Received: 296
    Given: 142
    Total Downloaded
    1.75 GB

    0 Not allowed!

    Default Re: How to invert just a bit - complement of a bit

    I'm ever so sorry. I forgot to look that this question was about the Proton24 compiler!

    I'll do some tests and get back to you.
    Last edited by top204; 18th July 2019 at 21:33.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,428
    Thumbs Up
    Received: 296
    Given: 142
    Total Downloaded
    1.75 GB

    0 Not allowed!

    Default Re: How to invert just a bit - complement of a bit

    You are correct kuhrig, the complement of a bit that is different to the assignment bit is not working as it should. I have now corrected it and will produce an update to teh compilers.

    It was caused by the Zero flag not being altered by some of the mnemonics used, even though the PIC24 datasheets state that it should be!

    I've also added a few extras to the compiler updates. For example, A timeout label in serial commands can now also be Break or Continue, so when inside a loop, a timeout will either exit the loop, or skip what else is in the loop and continue it.

    Dim Index as Byte = 0
    Dim MyVar as Byte
    Dim MyArray[20] as Byte

    Clear MyArray

    Do
    HSerin 1000, Break, [MyVar] ' Exit the loop if timed out
    If MyVar = 0 Then Break ' Exit the loop when a null received
    MyArray[Index] = MyArray ' Place the byte received into the array
    Loop

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. [SOLVED !] How to read 8-bit from 10-bit port?
      By qrppablo in forum Proton 24
      Replies: 4
      Last Post: 7th January 2019, 21:37
    2. SPI switching between 8 bit and 16 bit
      By pjdenyer in forum Third Party Support
      Replies: 3
      Last Post: 12th December 2015, 16:54
    3. 8 bit result from 10 bit ADC using Left justification
      By Stephen Moss in forum Proton Plus Compiler v3
      Replies: 2
      Last Post: 11th July 2006, 14:15
    4. [SOLVED !] 15-bit/20-bit Versions of Sony SIRC Protocol
      By insury in forum Proton-IR
      Replies: 1
      Last Post: 21st December 2004, 03:39
    5. Reading a/d with both 8 bit and 10 bit resolution
      By cgriffin in forum Proton Plus Compiler v3
      Replies: 0
      Last Post: 23rd November 2004, 23:19

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts