BITS.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef BITS_HEADER
  2. #define BITS_HEADER
  3. // this header needs
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include "../ARRAY.h"
  7. // bit and byte array, to hold bits or bytes read (large enough)
  8. // data will be stored in big endian mode as I read that way
  9. #define BYTE_HOLDER_LENGTH 64
  10. #define BIT_HOLDER_LENGTH (CHAR_BIT * BYTE_HOLDER_LENGTH)
  11. byte BYTE_HOLDER[BYTE_HOLDER_LENGTH] = {0};
  12. byte BIT_HOLDER[BIT_HOLDER_LENGTH] = {0};
  13. // clear the above arrays
  14. void clear_bit_holder(void);
  15. void clear_byte_holder(void);
  16. // print the above arrays
  17. void print_bit_holder(void);
  18. void print_byte_holder(void);
  19. // enum with bit shifting modes
  20. typedef enum
  21. {
  22. BITSHIFT_RIGHT,
  23. BITSHIFT_LEFT,
  24. } BITSHIFT_T;
  25. // bit shift functions for arrays (depend on SYS_ENDIAN)
  26. byte arr_bitshift(void * array, umax arr_size, umax var_size, BITSHIFT_T bitshift_type);
  27. void arr_n_bitshift(void * array, umax arr_size, umax var_size, BITSHIFT_T type, umax shift_count);
  28. byte arr_circ_bitshift(void * array, umax arr_size, umax var_size, BITSHIFT_T bitshift_type);
  29. void arr_n_circ_bitshift(void * array, umax arr_size, umax var_size, BITSHIFT_T bitshift_type, umax shift_count);
  30. // get bits from memory and store them in BIT_ARRAY
  31. smax get_bits(umax bit_cnt, umax lpad_cnt, void * src);
  32. // get bits from bytes in memory (but in a little more hardcore way)
  33. smax get_byte_bits(umax byte_cnt, umax lshifts, umax bit_cnt, umax lpad_cnt, void * src, ENDIAN_T endian);
  34. // write bits in memory (bits from BYTE_HOLDER)
  35. bool write_bits(umax bit_holder_pos, umax left_bitshifts, umax right_bitshifts, void * dest, ENDIAN_T dest_endian);
  36. #include "BITS.c"
  37. #endif // BITS_HEADER