00001
00002
00003 #include <stdint.h>
00004
00005 inline void endian_swap(unsigned short& x)
00006 {
00007 x = (x >> 8) |
00008 (x << 8);
00009 }
00010
00011 inline void endian_swap(unsigned int& x)
00012 {
00013 x = (x >> 24) |
00014 ((x << 8) & 0x00FF0000) |
00015 ((x >> 8) & 0x0000FF00) |
00016 (x << 24);
00017 }
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00036 inline unsigned int get_bits(const uint32_t& word, const unsigned int& offset, const unsigned int& nbits)
00037 {
00038 uint32_t mask = 0;
00039 for (unsigned int i = 0; i < nbits; i++)
00040 mask = (mask << 1) + 1;
00041 return (word >> offset) & mask;
00042 }
00043
00046 inline bool test_bit(const uint32_t& word, const unsigned int& bit)
00047 {
00048 uint32_t mask=1;
00049 mask = mask << bit;
00050 return (word & mask) == mask;
00051 }
00052
00055 inline unsigned int bcd2dec(const unsigned int code)
00056 {
00057 unsigned int dec = 0;
00058 unsigned int bcd = code;
00059 int index = 1;
00060 while(bcd != 0) {
00061 dec += (bcd & 0xf) * index;
00062 bcd = bcd >> 4;
00063 index *= 10;
00064 }
00065 return dec;
00066 }