uint8_t* buf_cpy(const uint8_t *from, uint8_t *to, int size)
{
- unsigned int num_bytes = CEIL(size, 8);
- unsigned int i;
-
if (from == NULL)
return NULL;
- for (i = 0; i < num_bytes; i++)
+ for (unsigned i = 0, num_bytes = CEIL(size, 8); i < num_bytes; i++)
to[i] = from[i];
/* mask out bits that don't belong to the buffer */
int buf_cmp(const uint8_t *buf1, const uint8_t *buf2, int size)
{
- int num_bytes = CEIL(size, 8);
- int i;
-
if (!buf1 || !buf2)
return 1;
- for (i = 0; i < num_bytes; i++)
+ for (unsigned i = 0, num_bytes = CEIL(size, 8); i < num_bytes; i++)
{
/* last byte */
/* mask out bits that don't really belong to the buffer if size isn't a multiple of 8 bits */
int buf_cmp_mask(const uint8_t *buf1, const uint8_t *buf2, const uint8_t *mask, int size)
{
- int num_bytes = CEIL(size, 8);
- int i;
-
- for (i = 0; i < num_bytes; i++)
+ for (unsigned i = 0, num_bytes = CEIL(size, 8); i < num_bytes; i++)
{
/* last byte */
/* mask out bits that don't really belong to the buffer if size isn't a multiple of 8 bits */
uint8_t* buf_set_ones(uint8_t *buf, int count)
{
- int num_bytes = CEIL(count, 8);
- int i;
-
- for (i = 0; i < num_bytes; i++)
+ for (unsigned i = 0, num_bytes = CEIL(count, 8); i < num_bytes; i++)
{
if (count >= 8)
buf[i] = 0xff;
uint8_t* buf_set_buf(const uint8_t *src, int src_start, uint8_t *dst, int dst_start, int len)
{
int src_idx = src_start, dst_idx = dst_start;
- int i;
- for (i = 0; i < len; i++)
+ for (int i = 0; i < len; i++)
{
if (((src[src_idx / 8] >> (src_idx % 8)) & 1) == 1)
dst[dst_idx / 8] |= 1 << (dst_idx % 8);
uint32_t flip_u32(uint32_t value, unsigned int num)
{
- uint32_t c;
-
- c = (bit_reverse_table256[value & 0xff] << 24) |
+ uint32_t c = (bit_reverse_table256[value & 0xff] << 24) |
(bit_reverse_table256[(value >> 8) & 0xff] << 16) |
(bit_reverse_table256[(value >> 16) & 0xff] << 8) |
(bit_reverse_table256[(value >> 24) & 0xff]);
int ceil_f_to_u32(float x)
{
- uint32_t y;
-
if (x < 0) /* return zero for negative numbers */
return 0;
- y = x; /* cut off fraction */
+ uint32_t y = x; /* cut off fraction */
if ((x - y) > 0.0) /* if there was a fractional part, increase by one */
y++;
buffer[1] = (value >> 8) & 0xff;
buffer[0] = (value >> 0) & 0xff;
} else {
- unsigned int i;
- for (i = first; i < first + num; i++)
+ for (unsigned i = first; i < first + num; i++)
{
if (((value >> (i - first)) & 1) == 1)
buffer[i / 8] |= 1 << (i % 8);
(((uint32_t)buffer[0]) << 0);
} else {
uint32_t result = 0;
- unsigned int i;
- for (i = first; i < first + num; i++)
+ for (unsigned i = first; i < first + num; i++)
{
if (((buffer[i / 8] >> (i % 8)) & 1) == 1)
result |= 1 << (i - first);