From 047b52250344ac6e341d4c7b03315bee1b422280 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Wed, 13 Aug 2008 02:12:37 +0000 Subject: Move bit masking functions to library git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@701 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- lib/util/bitarith.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lib/util/bitarith.h (limited to 'lib') diff --git a/lib/util/bitarith.h b/lib/util/bitarith.h new file mode 100644 index 00000000..4ed6c4c3 --- /dev/null +++ b/lib/util/bitarith.h @@ -0,0 +1,42 @@ +#ifndef BITARITH_H_INCLUDED +#define BITARITH_H_INCLUDED + +#include "pm_config.h" + +static __inline__ unsigned char +pm_byteLeftBits(unsigned char const x, + unsigned int const n) { +/*---------------------------------------------------------------------------- + Clear rightmost (8-n) bits, retain leftmost (=high) n bits. + + Return arbitrary value if n > 8. +-----------------------------------------------------------------------------*/ + unsigned char retval; + + retval = x; + retval >>= (8-n); + retval <<= (8-n); + + return retval; +} + + + +static __inline__ unsigned char +pm_byteRightBits(unsigned char const x, + unsigned int const n){ +/*---------------------------------------------------------------------------- + Return rightmost (=low) n bits of x. + + Return arbitrary value if n > 8. +-----------------------------------------------------------------------------*/ + unsigned char retval; + + retval = x; + retval <<= (8-n); + retval >>= (8-n); + + return retval; +} + +#endif -- cgit 1.4.1