inverting all bits in a byte


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,670


    Did you find this post helpful? Yes | No

    Default Re: inverting all bits in a byte

    how many bits in a byte ? not 9


    Eg %011010110 would become %100101001
    Strangely I can display the value of byteA in the display (LabX1) but ~byteA comes up empty.
    what display? , how displayed ?
    if its a common garden variety lcd , chrs in this range 127 < chr >160 are not in the built in font
    so using var A = $66
    A will print on lcd
    ~A ($99) will not print on lcd
    Warning I'm not a teacher

  2. #2
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: inverting all bits in a byte

    There is a simple ASM command, COMF. This is what it would look like:

    @ BANKSEL _byteA
    @ COMF _byteA, F

    The first line moves the BSR (Bank Select Register) to the BANK containing your variable. The variable is preceded by an underscore for ASM; _byteA.

    The second line executes the command, Compliment F (F is your variable). The appending ", F" puts the result back in your variable, byteA.

    Hope this helps

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: inverting all bits in a byte

    Use the ^ operator for Bitwise Exclusive OR

    ByteA = ByteA ^ %11111111 Inverts the bits of ByteA

  4. #4
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: inverting all bits in a byte

    thanks Dick

  5. #5
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: inverting all bits in a byte

    I have the new "enhanced" byte, with 9 bits.

  6. #6
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: inverting all bits in a byte

    Using comf would be about twice as fast there since you don’t have to do anything at all with the literal 0xFF.

Similar Threads

  1. An easy way to get bits to byte
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th November 2015, 11:16
  2. Problem with bits in byte array....
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 19th October 2011, 06:27
  3. Accessing several bits together in a byte or word...
    By rossfree in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th May 2007, 18:07
  4. Bits in Byte Arrays
    By crhomberg in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th April 2007, 22:37
  5. reading first four bits of a byte
    By kamet in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd January 2007, 08:50

Members who have read this thread : 1

You do not have permission to view the list of names.

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