Performing bitwise operations in C

Posts you want to find years later go here.
bob
Poser
Posts: 344
Joined: Fri Jul 18, 2003 1:26 am
Location: p-town, pa
Contact:

Post by bob »

Code: Select all



int thething(int n)
{
return nthbit(n,0) ^ nthbit(n,2) ^ nthbit(n,17);
}


bob
Poser
Posts: 344
Joined: Fri Jul 18, 2003 1:26 am
Location: p-town, pa
Contact:

Post by bob »

Shorter version for this particular case:

Code: Select all

int thething(int n) 
{ 
  return (n ^ (n>>2) ^ (n>>17))&1;
}

Jonathan
Grand Pooh-Bah
Posts: 6606
Joined: Tue Sep 19, 2006 8:45 pm
Location: Portland, OR
Contact:

Post by Jonathan »

Somewhat on topic, Perl 5.8 is not 64-bit safe! You think you're all fine with a 64 bit number encoded as a string, then you try to do math on it and you're screwed. A friend of mine threw together a 64 bit math library using bit arrays, but it is painfully slow when trying to do real work.

Math::BigInt is a step in the right direction, but I think it's useless when you're trying to do math on hex input to produce hex output.

quantus
Tenth Dan Procrastinator
Posts: 4853
Joined: Fri Jul 18, 2003 3:09 am
Location: San Jose, CA

Post by quantus »

Is there documentation of this somewhere?
Have you clicked today? Check status, then: People, Jobs or Roads

Dave
Tenth Dan Procrastinator
Posts: 3459
Joined: Fri Jul 18, 2003 3:40 pm

Post by Dave »

I just get annoyed that apparently these 64 bit machines can't connect to some printers/plotters.
It takes 43 muscles to frown and 17 to smile, but it doesn't take any to just sit there with a dumb look on your face.

Post Reply