Performing bitwise operations in C

Posts you want to find years later go here.

Postby bob » Mon Apr 24, 2006 4:23 am

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 12:26 am
Location: p-town, pa

Postby bob » Mon Apr 24, 2006 4:26 am

Shorter version for this particular case:
Code: Select all
int thething(int n)
{
  return (n ^ (n>>2) ^ (n>>17))&1;
}
bob
Poser
 
Posts: 344
Joined: Fri Jul 18, 2003 12:26 am
Location: p-town, pa

Postby Jonathan » Tue Feb 13, 2007 5:07 am

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.
Jonathan
Grand Pooh-Bah
 
Posts: 5946
Joined: Tue Sep 19, 2006 7:45 pm
Location: Portland, OR

Postby quantus » Tue Feb 13, 2007 7:29 pm

Is there documentation of this somewhere?
Have you clicked today? Check status, then: People, Jobs or Roads
User avatar
quantus
Tenth Dan Procrastinator
 
Posts: 4613
Joined: Fri Jul 18, 2003 2:09 am
Location: San Jose, CA

Postby Dave » Wed Feb 14, 2007 8:58 pm

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.
User avatar
Dave
Tenth Dan Procrastinator
 
Posts: 3324
Joined: Fri Jul 18, 2003 2:40 pm

Previous

Return to The Vault

Who is online

Users browsing this forum: No registered users and 2 guests