/* This program 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. This program 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 this program. If not, see . */ /* collection of bitwise and array-wise operations. */ #include "bitwise.h" void loadUint(uint8_t *b, uint32_t v, uint8_t bitCount, bool MSBfirst) { const uint8_t last = bitCount/8; for (uint8_t i=0; i> (8*idx); } } uint16_t fetchU16(const uint8_t *v, bool MSBfirst) { if (MSBfirst) { return v[1] | (v[0]<<8); } return v[0] | (v[1]<<8); } uint32_t fetchU24(const uint8_t *v, bool MSBfirst) { if (MSBfirst) { return v[2] | (v[1]<<8) | (v[0]<<16); } return v[0] | (v[1]<<8) | (v[2]<<16); } uint32_t fetchU32(const uint8_t *v, bool MSBfirst) { if (MSBfirst) { return v[3] | (v[2]<<8) | (v[1]<<16) | (v[0]<<24); } return v[0] | (v[1]<<8) | (v[2]<<16) | (v[3]<<24); }