ux500_swap_bits_in_byte(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ ux500_swap_bits_in_byte(9) ✨

okay bestie, so this one is from the Kernel API Manual and it's literally the cutest little bit-shuffler ever. we're talking ux500_swap_bits_in_byte β€” it mirrors the bits in a byte πŸ¦‹ like, full reverse-glow-up for your 8 little bits. no cap.


🌸 SYNOPSIS 🌸

u8 ux500_swap_bits_in_byte (u8 b );

that's it. that's the whole vibe. one byte in, one byte out. πŸ’…


πŸŽ€ ARGUMENTS πŸŽ€

  • b β€” the byte that's about to get mirrored. it's the main character of this whole operation, give it a little respect 🫢

πŸ’– DESCRIPTION πŸ’–

so the bits get swapped like this, and honestly the way that it works is kind of iconic. so b includes bits 0-7, right? then nibble 1 (n1) holds bits 0-3 and nibble 2 (n2) holds bits 4-7. two lil nibbles, each living their own life 😭

🧚 Nibble 1 (n1)

heads up bestie: the "old" (moved) bit gets replaced with a zero. so like, it does not survive the move, okay? it's giving farewell tour πŸ’€
  1. Move bit 6 and 7, 4 positions to the left.
  2. Move bit 3 and 5, 2 positions to the left.
  3. Move bit 1-4, 1 position to the left.

🧚 Nibble 2 (n2)

  1. Move bit 0 and 1, 4 positions to the right.
  2. Move bit 2 and 4, 2 positions to the right.
  3. Move bit 3-6, 1 position to the right.

then you combine the two nibbles into one complete, fully swapped byte. that's the finale ✨ the two halves reunite and it's beautiful. reunion episode energy fr fr πŸ˜­πŸ’–


πŸ¦‹ SEE ALSO πŸ¦‹

  • Kernel file ./drivers/crypto/stm32/stm32-cryp.c
  • ux500_swizzle_key(9) β€” the sibling, obviously πŸ‘‘

signed off with love from the ./drivers/crypto/stm32 corner of the kernel πŸ’… that's October 2026 energy for ya 🌈

πŸ“¦ where this page comes from