Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

66%
+2 −0
Challenges Reverse the bits in a Byte

ARM Thumb machine code, 6 bytes 0: fa90 f0a0 rbit r0, r0 // reverse bits in 32-bit register 0 4: 4770 bx lr // return if bytes have to be octets (8-bit): ARM Thumb machine code...

posted 1y ago by lovebuny‭  ·  edited 1y ago by lovebuny‭

Answer
#3: Post edited by user avatar lovebuny‭ · 2023-09-08T23:52:22Z (over 1 year ago)
less whitespace
  • # ARM Thumb machine code, 6 bytes
  • ```asm
  • 0: fa90 f0a0 rbit r0, r0 // reverse bits in 32-bit register 0
  • 4: 4770 bx lr // return
  • ```
  • if bytes have to be octets (8-bit):
  • # ARM Thumb machine code, 8 bytes
  • ```asm
  • 0: fa90 f0a0 rbit r0, r0 // reverse bits in 32-bit register 0
  • 4: 0e00 lsrs r0, r0, #24 // shift it right by 24 bits
  • 6: 4770 bx lr // return
  • ```
  • # ARM Thumb machine code, 6 bytes
  • ```asm
  • 0: fa90 f0a0 rbit r0, r0 // reverse bits in 32-bit register 0
  • 4: 4770 bx lr // return
  • ```
  • if bytes have to be octets (8-bit):
  • # ARM Thumb machine code, 8 bytes
  • ```asm
  • 0: fa90 f0a0 rbit r0, r0 // reverse bits in 32-bit register 0
  • 4: 0e00 lsrs r0, r0, #24 // shift it right by 24 bits
  • 6: 4770 bx lr // return
  • ```
#2: Post edited by user avatar lovebuny‭ · 2023-09-08T23:16:06Z (over 1 year ago)
32-bit byte?
  • # ARM Thumb machine code, 8 bytes
  • ```asm
  • 0: fa90 f0a0 rbit r0, r0 // reverse bits in 32-bit register 0
  • 4: 0e00 lsrs r0, r0, #24 // shift it right by 24 bits
  • 6: 4770 bx lr // return
  • ```
  • # ARM Thumb machine code, 6 bytes
  • ```asm
  • 0: fa90 f0a0 rbit r0, r0 // reverse bits in 32-bit register 0
  • 4: 4770 bx lr // return
  • ```
  • if bytes have to be octets (8-bit):
  • # ARM Thumb machine code, 8 bytes
  • ```asm
  • 0: fa90 f0a0 rbit r0, r0 // reverse bits in 32-bit register 0
  • 4: 0e00 lsrs r0, r0, #24 // shift it right by 24 bits
  • 6: 4770 bx lr // return
  • ```
#1: Initial revision by user avatar lovebuny‭ · 2023-09-08T14:43:27Z (over 1 year ago)
# ARM Thumb machine code, 8 bytes

```asm
0: fa90 f0a0  rbit  r0, r0      // reverse bits in 32-bit register 0
4: 0e00       lsrs  r0, r0, #24 // shift it right by 24 bits
6: 4770       bx    lr          // return
```