Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 10:22 26 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : bit swap in byte

     Page 2 of 2    
Author Message
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1133
Posted: 06:28pm 27 Jul 2022
Copy link to clipboard 
Print this post

  matherp said  Just do it on each byte in turn and then swap the bytes end to end

Again: your solution is elegant.

I think we will lost the speed advantage if we do the operation 8 times.
8 * 15us would be 120us (or more) vs. 30us for the CSub solution.

Kind regards
Michael

EDIT:
Anyway a good solution for Gerald!
Edited 2022-07-28 04:30 by twofingers
 
ville56
Regular Member

Joined: 08/06/2022
Location: Austria
Posts: 68
Posted: 06:56pm 27 Jul 2022
Copy link to clipboard 
Print this post

indeed it is refreshing for my mind to see all the different solutions. It leads me away from my old and small paths of thinking for this particular problem. This forum is really world class with all its potential.

@twofingers: thanks for the cookbook to csub :-), i really appreciate it. Have to dive into it deeper, but at the moment i have to spend some time on servicing my motorbike for my annual statutorial inspection.

Regards and thanks,
Gerald
                                                                 
73 de OE1HGA, Gerald
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1133
Posted: 06:58pm 27 Jul 2022
Copy link to clipboard 
Print this post

@Gerald
Viel Glück beim TÜV!
 
ville56
Regular Member

Joined: 08/06/2022
Location: Austria
Posts: 68
Posted: 07:45pm 27 Jul 2022
Copy link to clipboard 
Print this post

Danke!
                                                                 
73 de OE1HGA, Gerald
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1133
Posted: 11:43am 28 Jul 2022
Copy link to clipboard 
Print this post

Just to complete this topic. A version for 8-bits reversing:

8Bitorderreverse.zip

On a 378MHz PicoMite reversing the bit order for a Byte takes 12us.

Regards
Michael

edit:
Just to clarify: I think Peter's solution is the better one.
Edited 2022-07-28 22:24 by twofingers
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 326
Posted: 03:05pm 28 Jul 2022
Copy link to clipboard 
Print this post

Here's one way:

10 INPUT "Enter a number:",n:print
20 h$=right$("0000"+hex$(n),4)
30 PRINT h$
40 h$=right$(h$,2)+left$(h$,2)
50 nr=val("&h"+h$)
60 PRINT h$
70 PRINT nr
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024