00001 //---------------------------------------------------------------------------- 00002 /** @file 00003 */ 00004 //---------------------------------------------------------------------------- 00005 00006 #include "Misc.hpp" 00007 00008 using namespace benzene; 00009 00010 //---------------------------------------------------------------------------- 00011 00012 void MiscUtil::WordToBytes(unsigned word, byte* out) 00013 { 00014 for (int i=0; i<4; i++) { 00015 out[i] = static_cast<byte>(word & 0xff); 00016 word>>=8; 00017 } 00018 } 00019 00020 unsigned MiscUtil::BytesToWord(const byte* bytes) 00021 { 00022 unsigned ret=0; 00023 for (int i=3; i>=0; i--) { 00024 ret <<= 8; 00025 ret |= bytes[i]; 00026 } 00027 return ret; 00028 } 00029 00030 int MiscUtil::NumBytesToHoldBits(int bits) 00031 { 00032 return (bits+7)/8; 00033 } 00034 00035 //---------------------------------------------------------------------------- 00036