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
31 lines
1.0 KiB
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
#define BITVAL(code, off) ((code & (1 << off)) >> off)
|
|
|
|
void decode(uint32_t rawcode) {
|
|
// Lot:3:6
|
|
// bit3->bit3, bit4->bit2, bit5->bit1, bit6->bit0
|
|
uint32_t lot = 0;
|
|
lot = BITVAL(rawcode, 3) << 3 | BITVAL(rawcode, 4) << 2 | BITVAL(rawcode, 5) << 1 | BITVAL(rawcode, 6) << 0;
|
|
|
|
// =(bit1)*2^6+(bit2)*2^5+(bit11)*2^4+(bit10)*2^0+(bit9)*2^1+(bit8)*2^2+(bit7)*2^3
|
|
|
|
uint32_t item = 0;
|
|
item = (BITVAL(rawcode, 1) << 6) //
|
|
| (BITVAL(rawcode, 2) << 5) //
|
|
| (BITVAL(rawcode, 11) << 4) //
|
|
| (BITVAL(rawcode, 10) << 0) //
|
|
| (BITVAL(rawcode, 9) << 1) //
|
|
| (BITVAL(rawcode, 8) << 2) //
|
|
| (BITVAL(rawcode, 7) << 3);
|
|
|
|
printf(" item-lot: %d-%d\n", item, lot);
|
|
}
|
|
int main(int argc, char const *argv[]) {
|
|
decode(0x48C1); // 0x48C1 100 1000 1100 0001 ,expect24-1
|
|
decode(0x443B); // 0x443B 100 0100 0011 1011 ,expect65-14
|
|
decode(0x45c1); // 0x443B 100 0100 0011 1011 ,expect65-14
|
|
|
|
return 0;
|
|
}
|