Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

What are your favorite bit hacks?

Name: Anonymous 2023-06-27 1:10

Besides the obvious set/get/clear bit mask (e.g. byte |= (1 << bit_we_want_to_set)).

Mine would be determining if an integer is a power of 2. Instead of using some
unnecessary complex loop, we simply do:
x && ((x & (x - 1)) == 0);

Simple, but clever. If you are nub (most likely are), read up more on bit manipulation/twiddling/hack, etc.

Name: Anonymous 2023-06-27 22:10

Who you calling a nub?

Name: Anonymous 2023-06-28 0:17

>>2
You. Nub.

Name: Anonymous 2023-06-28 10:29

>>3
I'll have you know I graduated top of my class in the bit twiddlers and I have performed over one hundred bit twiddles, and that is just with my pen and paper.

Name: Anonymous 2023-06-28 10:43

>>4
How do you do that with pen and paper? I have to use gamma particles.

Name: Anonymous 2023-06-28 13:54

>>4
Only one hundred? Lol.

Name: Anonymous 2023-06-28 22:29

log_2(x)%1==0

Name: Anonymous 2023-06-29 11:07

I only use those for bitfields

Name: Anonymous 2023-07-02 12:25

I like to use
(a ^ b ^ a) << (c^c)
if I need the identity operation in a quick and dirty way. Sure, there might be better ways to implement identity, but this works for me.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List