about summary refs log tree commit diff
path: root/lib/util/bitarith.h
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2008-09-27 02:59:58 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2008-09-27 02:59:58 +0000
commit4b4b88014200757f6f7f8864c85138a56835c794 (patch)
treecea2a438b384f7a4fbf85aabb9fbd23093908d49 /lib/util/bitarith.h
parentf04d41f61e5cf83835c6bc85122e65cfe2cf9857 (diff)
downloadnetpbm-mirror-4b4b88014200757f6f7f8864c85138a56835c794.tar.gz
netpbm-mirror-4b4b88014200757f6f7f8864c85138a56835c794.tar.xz
netpbm-mirror-4b4b88014200757f6f7f8864c85138a56835c794.zip
Rebase to 10.44.00
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@738 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/util/bitarith.h')
-rw-r--r--lib/util/bitarith.h42
1 files changed, 42 insertions, 0 deletions
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