[SOLVED !] How to invert BYTE order


Today 18:19
Forum: Proton Plus Compiler v3
Starter: Les
Views: 0
Replies: 16
Today 15:54
Forum: GPS
Starter: SimonJA
Views: 0
Replies: 14
Go to last post By: tumbleweed
Today 14:37
Forum: The Lounge
Starter: towlerg
Views: 0
Replies: 1
Go to last post By: fanie
Today 14:10
Forum: The Lounge
Starter: John Drew
Views: 0
Replies: 12
Today 12:55
Forum: The Lounge
Starter: fanie
Views: 0
Replies: 18
Today 02:12
Forum: The Lounge
Starter: towlerg
Views: 0
Replies: 5
Today 01:13
Forum: The Lounge
Starter: Tim
Views: 0
Replies: 25
Yesterday 19:17
Forum: The Lounge
Starter: basparky
Views: 0
Replies: 14
Closed Thread
Results 1 to 8 of 8

Thread: How to invert BYTE order13 days old

  1. #1
    Junior Member qrppablo's Avatar
    Join Date
    Jan 2019
    Posts
    5
    Thumbs Up
    Received: 1
    Given: 2
    Total Downloaded
    0

    0 Not allowed!

    Default How to invert BYTE order

    I have a BYTE variable equal to %01101001 and I need to invert the order, bit 7 to bit 0, bit 6 to bit 1, and so on. %01101001 to %10010110. How can I achieve this? using bitwise <<?

  2. 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. #2
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    778
    Thumbs Up
    Received: 23
    Given: 14
    Total Downloaded
    640.36 MB

    0 Not allowed!

    Default Re: How to invert BYTE order

    Bitwise Complement '~' Reverses the bits in a variable.

  4. 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. #3
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,232
    Thumbs Up
    Received: 76
    Given: 37
    Total Downloaded
    2.84 GB

    0 Not allowed!

    Default Re: How to invert BYTE order

    I think he wanted to swap the positions of the bits, not invert the whole thing,
    Les did a smart routine some time ago but I can't remember where.

    Charlie

  6. 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.

  7. #4
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,232
    Thumbs Up
    Received: 76
    Given: 37
    Total Downloaded
    2.84 GB

    0 Not allowed!

    Default Re: How to invert BYTE order

    Try something like this:

    Dim AAA As Byte 'the byte you want to reverse
    Dim BBB As Byte 'reversed result
    Dim K As Byte
    Dim MyBit As Bit 'work bit

    For K = 0 To 7
    MyBit = GetBit AAA, K
    LoadBit BBB, 7 - K, MyBit
    Next

  8. 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.

  9. #5
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,068
    Thumbs Up
    Received: 336
    Given: 126
    Total Downloaded
    1.52 GB

    2 Not allowed!

    Default Using the compiler's Rev operator to reverse the order of bits in a variable

    That's exactly what the Rev operator does, which is the '@' character within an expression. It reverses the order of the bits, and does not just do a complement of them. See page 63 in the compiler's manual:

    Example:
    Code:
    Dim MyByte as Byte = $03     ' Create and load MyByte with the binary value of 00000011
    
    MyByte = MyByte @ 8          ' MyByte now holds the binary value of 11000000
    The above will reverse the order of 8-bits of the variable MyByte (LSB first), and make MyByte hold $C0 when it is completed, which is binary 11000000
    Last edited by Les; 8th January 2019 at 10:47.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  10. 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.

  11. #6
    Senior Member dolci's Avatar
    Join Date
    Aug 2002
    Posts
    464
    Thumbs Up
    Received: 3
    Given: 2
    Total Downloaded
    1.53 GB

    1 Not allowed!

    Default Re: Using the compiler's Rev operator to reverse the order of bits in a variable

    I think this is what he meant

    Dim Var1 As Byte
    Dim Var2 As Byte

    Var1= %01101111
    Print At 1,1,Bin8 Var1 ; result is 01101111
    Var2 = ~Var1
    Print At 2,1,Bin8 Var2 ; result is 10010000

    Stop
    Last edited by dolci; 11th January 2019 at 13:38.
    [SIGPIC][/SIGPIC]

  12. 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.

  13. #7
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    778
    Thumbs Up
    Received: 23
    Given: 14
    Total Downloaded
    640.36 MB

    0 Not allowed!

    Default Re: Using the compiler's Rev operator to reverse the order of bits in a variable

    Dolci, I thought that too, at first glance the byte example given is quite close to inverting the bits, but it does say invert the order.... my excuse was first thing in the morning and no coffee

  14. 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.

  15. #8
    Junior Member qrppablo's Avatar
    Join Date
    Jan 2019
    Posts
    5
    Thumbs Up
    Received: 1
    Given: 2
    Total Downloaded
    0

    0 Not allowed!

    Default Re: Using the compiler's Rev operator to reverse the order of bits in a variable

    Quote Originally Posted by Les View Post
    That's exactly what the Rev operator does, which is the '@' character within an expression. It reverses the order of the bits, and does not just do a complement of them. See page 63 in the compiler's manual:

    Example:
    Code:
    Dim MyByte as Byte = $03     ' Create and load MyByte with the binary value of 00000011
    
    MyByte = MyByte @ 8          ' MyByte now holds the binary value of 11000000
    The above will reverse the order of 8-bits of the variable MyByte (LSB first), and make MyByte hold $C0 when it is completed, which is binary 11000000
    It works, thank you!
    Last edited by qrppablo; 13th January 2019 at 06:03.

  16. 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. Math operators - order of precedence
    By wastrix in forum Proton Plus Compiler v3
    Replies: 5
    Last Post: 9th November 2016, 15:44
  2. HRSout and HSerOut byte order
    By rcurl in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 21st August 2016, 09:02
  3. IMO: Backwards thread order
    By pciebiera in forum Website / Forum Issues
    Replies: 0
    Last Post: 15th March 2010, 15:53
  4. compiler wish: Word byte order consistency
    By cgriffin in forum Wish List / Product Feedback
    Replies: 1
    Last Post: 29th June 2007, 22:38
  5. optimizing Dim order
    By wtriska in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 13th June 2005, 10:05

Posting Permissions

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