bitmap_cut(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… bitmap_cut(9) β€” the Kernel API Manual, but make it make sense ✨

okay bestie, so we're in the bitmap_cut(9) page of the Kernel API Manual and honestly? this one is lowkey iconic once you see it. it's a little helper that goes βœ‚οΈ snip snip on a chunk of bits and then scooches everything leftward to close the gap. no cap, it's giving scissors-emoji energy. πŸŽ€


✨ NAME ✨

bitmap_cut β€” remove bit region from bitmap and right shift remaining bits πŸ¦‹

like, literally: you pick a region, you cut it out, and the rest of the bits shift over to the right to fill the hole. periodt. πŸ’œ


🌸 SYNOPSIS 🌸

void bitmap_cut (unsigned long *dst , const unsigned long *src ,
       unsigned int first , unsigned int cut , unsigned int nbits );

(yes the spaces before those commas are exactly like that, don't come for me, it's literally the API πŸ’€)


🫢 ARGUMENTS 🫢

  • dst β€” the destination bitmap, and heads up bestie it might overlap with src πŸ‘€ (more on that down below, it's fine, it's fine)
  • src β€” the source bitmap, your original bits, the main character πŸ’–
  • first β€” start bit of region to be removed β€” this is where the cutting begins βœ‚οΈ
  • cut β€” number of bits to remove, i.e. how many bits we're yeeting 🌈
  • nbits β€” bitmap size, in bits ⭐

πŸ‘‘ DESCRIPTION πŸ‘‘

so here's the whole vibe, stated precisely so you can trust me: set the n-th bit of dst iff the n-th bit of src is set and n is less than first, or the m-th bit of src is set for any m such that first <= n < nbits, and m = n + cut.

read it twice, it'll click, i promise 🧚 and now the part that actually makes it click β€” pictures!! πŸ–ΌοΈ

in pictures, example for a big-endian 32-bit architecture:

the src bitmap is:

         31                                   63
         |                                    |
         10000000 11000001 11110010 00010101  10000000 11000001 01110010 00010101
                         |  |              |                                    |
                        16  14             0                                   32

if cut is 3, and first is 14, bits 14-16 in src are cut and dst is:

         31                                   63
         |                                    |
         10110000 00011000 00110010 00010101  00010000 00011000 00101110 01000010
                            |              |                                    |
                            14 (bit 17     0                                   32
                                from src)

see how bit 17 from src slid into spot 14? that's the shift-and-carry doing its lil dance πŸ’ƒ slay.

πŸ’€ important vibes: note that dst and src might overlap partially or entirely. not a typo, not a drill β€” it's literally fine, that's the design.

and how's it built? this is implemented in the obvious way, with a shift and carry step for each moved bit πŸ”₯ optimisation is left as an exercise for the compiler 😌 (the compiler is the one doing homework around here, not us)


πŸ” SEE ALSO πŸ”

go off, bestie, here's the whole friend group πŸ’…:


and that's the whole page, bestie!! πŸ₯³ this legendary lil slice lives in ./lib and was stamped October 2026 β€” so go forth, cut those bits, shift those bits, and remember: overlap is allowed and you're doing amazing πŸ«ΆπŸ’– ✨

πŸ“¦ where this page comes from