Skip to content

Commit

Permalink
fixed bit helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
256dpi committed Oct 24, 2017
1 parent 9b50975 commit 72231e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include "helpers.h"

uint8_t lwmqtt_read_bits(uint8_t byte, uint8_t pos, uint8_t num) {
return (byte & (uint8_t)((~((~0) << num)) << pos)) >> pos;
uint8_t lwmqtt_read_bits(uint8_t byte, int pos, int num) {
return (byte & (uint8_t)((~(0xFF << num)) << pos)) >> pos;
}

void lwmqtt_write_bits(uint8_t *byte, uint8_t value, uint8_t pos, uint8_t num) {
*byte = (*byte & ~(uint8_t)((~((~0) << num)) << pos)) | (value << pos);
void lwmqtt_write_bits(uint8_t *byte, uint8_t value, int pos, int num) {
*byte = (*byte & ~(uint8_t)((~(0xFF << num)) << pos)) | (value << pos);
}

lwmqtt_err_t lwmqtt_read_data(uint8_t **buf, const uint8_t *buf_end, uint8_t **data, size_t len) {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @param num - The number of bits to read.
* @return The read bits as a byte.
*/
uint8_t lwmqtt_read_bits(uint8_t byte, uint8_t pos, uint8_t num);
uint8_t lwmqtt_read_bits(uint8_t byte, int pos, int num);

/**
* Write bits to a byte.
Expand All @@ -21,7 +21,7 @@ uint8_t lwmqtt_read_bits(uint8_t byte, uint8_t pos, uint8_t num);
* @param pos - The position of the first bit.
* @param num - The number of bits to write.
*/
void lwmqtt_write_bits(uint8_t *byte, uint8_t value, uint8_t pos, uint8_t num);
void lwmqtt_write_bits(uint8_t *byte, uint8_t value, int pos, int num);

/**
* Reads arbitrary data from the specified buffer. The pointer is incremented by bytes read.
Expand Down

0 comments on commit 72231e0

Please sign in to comment.