You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.0 KiB

2 years ago
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #define BITVAL(code, off) ((code & (1 << off)) >> off)
  4. void decode(uint32_t rawcode) {
  5. // Lot:3:6
  6. // bit3->bit3, bit4->bit2, bit5->bit1, bit6->bit0
  7. uint32_t lot = 0;
  8. lot = BITVAL(rawcode, 3) << 3 | BITVAL(rawcode, 4) << 2 | BITVAL(rawcode, 5) << 1 | BITVAL(rawcode, 6) << 0;
  9. // =(bit1)*2^6+(bit2)*2^5+(bit11)*2^4+(bit10)*2^0+(bit9)*2^1+(bit8)*2^2+(bit7)*2^3
  10. uint32_t item = 0;
  11. item = (BITVAL(rawcode, 1) << 6) //
  12. | (BITVAL(rawcode, 2) << 5) //
  13. | (BITVAL(rawcode, 11) << 4) //
  14. | (BITVAL(rawcode, 10) << 0) //
  15. | (BITVAL(rawcode, 9) << 1) //
  16. | (BITVAL(rawcode, 8) << 2) //
  17. | (BITVAL(rawcode, 7) << 3);
  18. printf(" item-lot: %d-%d\n", item, lot);
  19. }
  20. int main(int argc, char const *argv[]) {
  21. decode(0x48C1); // 0x48C1 100 1000 1100 0001 ,expect24-1
  22. decode(0x443B); // 0x443B 100 0100 0011 1011 ,expect65-14
  23. decode(0x45c1); // 0x443B 100 0100 0011 1011 ,expect65-14
  24. return 0;
  25. }