ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/proj/globalhs/apps/calversfunctions.c
(Generate patch)

Comparing proj/globalhs/apps/calversfunctions.c (file contents):
Revision 1.1 by tplarson, Mon Sep 24 20:05:43 2012 UTC vs.
Revision 1.2 by tplarson, Thu Jan 24 06:41:12 2013 UTC

# Line 2 | Line 2
2   the following function is taken directly from chapter 2 of Kernighan and Ritchie
3   getbits: get n bits from position p
4   */
5 < unsigned getbits(unsigned x, int p, int n)
5 > unsigned long long getbits(unsigned long long x, int p, int n)
6   {
7 <  return (x >> (p+1-n)) & ~(~0 << n);
7 >  return (x >> (p+1-n)) & ~(~0ull << n);
8   }
9  
10   /*
11   Richard Heathfield's solution to exercise 2-6 of K&R
12   */
13 < unsigned setbits(unsigned x, int p, int n, unsigned y)
13 > unsigned long long setbits(unsigned long long x, int p, int n, unsigned long long y)
14   {
15 <  return (x & ((~0 << (p + 1)) | (~(~0 << (p + 1 - n))))) | ((y & ~(~0 << n)) << (p + 1 - n));
16 < // another solution (unchecked):
17 < //return (x & ~(~(~0<<n)<<p) | (y&~(~0<<n)) << p);
15 >  return (x & ((~0ull << (p + 1)) | (~(~0ull << (p + 1 - n))))) | ((y & ~(~0ull << n)) << (p + 1 - n));
16 > // another solution (untested):
17 > //return (x & ~(~(~0<<n)<<(p+1)) | (y&~(~0<<n)) << (p+1));
18   }
19  
20   unsigned long long fixcalver64(unsigned long long x)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines