(file) Return to calversfunctions.c CVS log (file) (dir) Up to [Development] / JSOC / proj / globalhs / apps

File: [Development] / JSOC / proj / globalhs / apps / calversfunctions.c (download)
Revision: 1.3, Sun Apr 28 06:58:43 2013 UTC (4 years, 11 months ago) by tplarson
Branch: MAIN
CVS Tags: globalhs_version_9, globalhs_version_8, globalhs_version_7, globalhs_version_6, globalhs_version_5, globalhs_version_4, globalhs_version_3, globalhs_version_2, globalhs_version_19, globalhs_version_18, globalhs_version_17, globalhs_version_16, globalhs_version_15, globalhs_version_14, globalhs_version_13, globalhs_version_12, globalhs_version_11, globalhs_version_10, globalhs_version_1, globalhs_version_0, Ver_LATEST, Ver_9-1, Ver_9-0, Ver_8-8, Ver_8-7, Ver_8-6, Ver_8-5, Ver_8-4, Ver_8-3, Ver_8-2, Ver_8-12, Ver_8-11, Ver_8-10, Ver_8-1, HEAD
Changes since 1.2: +2 -0 lines
added string to track cvs versions

char *cvsinfo = "cvsinfo: $Header: /home/cvsuser/cvsroot/JSOC/proj/globalhs/apps/calversfunctions.c,v 1.3 2013/04/28 07:58:43 tplarson Exp $";

/* 
the following function is taken directly from chapter 2 of Kernighan and Ritchie
getbits: get n bits from position p
*/
unsigned long long getbits(unsigned long long x, int p, int n)
{
  return (x >> (p+1-n)) & ~(~0ull << n);
}

/*
Richard Heathfield's solution to exercise 2-6 of K&R 
*/
unsigned long long setbits(unsigned long long x, int p, int n, unsigned long long y)
{
  return (x & ((~0ull << (p + 1)) | (~(~0ull << (p + 1 - n))))) | ((y & ~(~0ull << n)) << (p + 1 - n));
// another solution (untested):
//return (x & ~(~(~0<<n)<<(p+1)) | (y&~(~0<<n)) << (p+1));
}

unsigned long long fixcalver64(unsigned long long x)
{
  int firstnibble = getbits(x,3,4);
  if (firstnibble == 0)
    return setbits(x,3,4,2);
  else
    return x;
}



Karen Tian
Powered by
ViewCVS 0.9.4