mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-27 17:43:07 +08:00
revert: add reflect function since its used in crc.c
This commit is contained in:
parent
cf44d04be1
commit
57df6a1a7e
2 changed files with 18 additions and 0 deletions
|
@ -13,6 +13,23 @@ size_t nbytes(size_t nbits) {
|
|||
return (nbits >> 3)+((nbits % 8) > 0);
|
||||
}
|
||||
|
||||
/*
|
||||
ref http://www.csm.ornl.gov/~dunigan/crc.html
|
||||
Returns the value v with the bottom b [0,32] bits reflected.
|
||||
Example: reflect(0x3e23L,3) == 0x3e26
|
||||
*/
|
||||
uint32_t reflect(uint32_t v, int b) {
|
||||
uint32_t t = v;
|
||||
for ( int i = 0; i < b; ++i) {
|
||||
if (t & 1)
|
||||
v |= BITMASK((b-1)-i);
|
||||
else
|
||||
v &= ~BITMASK((b-1)-i);
|
||||
t>>=1;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
uint8_t reflect8(uint8_t b) {
|
||||
return ((b * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
size_t nbytes(size_t nbits);
|
||||
|
||||
extern uint32_t reflect(uint32_t v, int b); // used in crc.c ...
|
||||
extern uint8_t reflect8(uint8_t b); // dedicated 8bit reversal
|
||||
extern uint16_t reflect16(uint16_t b); // dedicated 16bit reversal
|
||||
|
||||
|
|
Loading…
Reference in a new issue