From 09b2f5ae0ff94e7eb97bf18dba20f993f78434b0 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 29 Aug 2011 14:38:47 +1000 Subject: [PATCH] Add bit manipulation convenience defines --- Makefile.am | 2 ++ bitwise.cpp | 22 ++++++++++++++++++++++ bitwise.hpp | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 bitwise.cpp create mode 100644 bitwise.hpp diff --git a/Makefile.am b/Makefile.am index 9e4b650e..299493ea 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,6 +9,7 @@ SUBDIRS = test UTIL_INCLUDE = \ annotations.hpp \ backtrace.hpp \ + bitwise.hpp \ debug.hpp \ enable_if.hpp \ endian.hpp \ @@ -35,6 +36,7 @@ UTIL_INCLUDE = \ version.hpp UTIL_FILES = \ + bitwise.cpp \ debug.cpp \ endian.cpp \ except.cpp \ diff --git a/bitwise.cpp b/bitwise.cpp new file mode 100644 index 00000000..5d732e9f --- /dev/null +++ b/bitwise.cpp @@ -0,0 +1,22 @@ +/* + * This file is part of libgim. + * + * libgim is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * libgim is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with libgim. If not, see . + * + * Copyright 2010 Danny Robson + */ + +#include "bitwise.hpp" + + diff --git a/bitwise.hpp b/bitwise.hpp new file mode 100644 index 00000000..cad09b86 --- /dev/null +++ b/bitwise.hpp @@ -0,0 +1,37 @@ +/* + * This file is part of libgim. + * + * libgim is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * libgim is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with libgim. If not, see . + * + * Copyright 2010 Danny Robson + */ + +#ifndef __UTIL_BITWISE_HPP +#define __UTIL_BITWISE_HPP + +#include + +const uint8_t BITMASK_1BITS = 0x01; +const uint8_t BITMASK_2BITS = 0x03; +const uint8_t BITMASK_3BITS = 0x07; +const uint8_t BITMASK_4BITS = 0x0F; +const uint8_t BITMASK_5BITS = 0x1F; +const uint8_t BITMASK_6BITS = 0x3F; +const uint8_t BITMASK_7BITS = 0x7F; +const uint8_t BITMASK_8BITS = 0xFF; + + + +#endif +