bit order inverting


Closed Thread
Results 1 to 5 of 5
  1. #1
    Macgman2000's Avatar
    Macgman2000 Guest

    Question bit order inverting

    Hello,

    What is the quickest way to invert the order of bits in an 8bit register? Currently I have data that is essentially backwards in order...IE, LSB is in the MSB poisition and MSB is in the LSB position.....

    TempVar = 11011010, I want to flip it to this FinalVar= 01011011

    Best Regards,
    Nick

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    in a loop.. well i guess.
    Code:
    for BitToShift=0 to 7
        FinalVar.0[7-BitToShift]=InitialVar.0[BitToShift]
        next
    There's probably a tons of way but this is the first who comes..
    Last edited by mister_e; - 27th July 2005 at 16:41.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Nick,

    Nick
    What is the quickest way to invert the order of bits in an 8bit register? Currently I have data that is essentially backwards in order...IE, LSB is in the MSB poisition and MSB is in the LSB position.....

    TempVar = 11011010, I want to flip it to this FinalVar= 01011011

    First off:
    to invert the bits you subtract from 255
    TembVar=255-TembVar

    11011010 would become 00100101

    Second off:

    Your example is NOT a switch of LSB/MSB

    11011010 would be 10101101

    The Rev command could be used.... you would reverse bits.

    (right out of the manual)
    B0 = %10101100 REV 4 (You would use 8)

    Your example shows this... Is this what you want?

    Edit: (I notice Steve and I were looking at the exact same forum thread in which we were playing with reversing strings....) Steve you is fast!

    DWayne
    Last edited by Dwayne; - 27th July 2005 at 17:00.
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Wink

    Dwayne...you're not only hearing impaired, your blind too ROFL... just kidding
    TempVar = 11011010, I want to flip it to this FinalVar= 01011011
    Bit7 will be Bit0 and so on
    Quote Originally Posted by Dwayne
    Edit: (I notice Steve and I were looking at the exact same forum thread in which we were playing with reversing strings....) Steve you is fast!
    Sometime i just sit in the Who's online and look what's happening... no secret

    BUT Yeah you're right REV will do the job. I never used it before 'cause i never had to swap bits. YEAH STEVE RTFM!!!

    I post this picture for me...
    Attached Images Attached Images  
    Last edited by mister_e; - 27th July 2005 at 17:11.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Macgman2000's Avatar
    Macgman2000 Guest


    Did you find this post helpful? Yes | No

    Default bit order inverting

    Actually I clocked in data to a Temp Variable. The data came in lsb first. So in actuality I want the mirror image of the bit order. Example:

    TempVar=11000001....this was shifted in lsb first, 8x so lsb is now in msb position.

    I want it to be msb in msb position......FinalVar=10000011. I will try out your suggestion. Thanks!


    Best Regards,
    Nick

Similar Threads

  1. decoding quadrature encoders
    By ice in forum mel PIC BASIC Pro
    Replies: 93
    Last Post: - 28th February 2017, 09:02
  2. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  3. Doubt with interrupt on change
    By lugo.p in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th March 2010, 15:22
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01: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