mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-21 06:35:04 +08:00
adapt reflect8 fct
This commit is contained in:
parent
9d204897d1
commit
791afef728
1 changed files with 15 additions and 0 deletions
|
@ -60,9 +60,21 @@ uint32_t reflect(uint32_t v, int b) {
|
|||
return v;
|
||||
}
|
||||
|
||||
// https://graphics.stanford.edu/~seander/bithacks.html#BitReverseTable
|
||||
|
||||
// Reverse the bits in a byte with 3 operations (64-bit multiply and modulus division):
|
||||
uint8_t reflect8(uint8_t b) {
|
||||
return (b * 0x0202020202ULL & 0x010884422010ULL) % 1023;
|
||||
}
|
||||
|
||||
|
||||
// Reverse the bits in a byte with 4 operations (64-bit multiply, no division):
|
||||
/*
|
||||
uint8_t reflect8(uint8_t b) {
|
||||
return ((b * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32;
|
||||
}
|
||||
*/
|
||||
|
||||
uint16_t reflect16(uint16_t b) {
|
||||
uint16_t v = 0;
|
||||
v |= (b & 0x8000) >> 15;
|
||||
|
@ -117,10 +129,13 @@ void lsl(uint8_t *data, size_t len) {
|
|||
data[len - 1] <<= 1;
|
||||
}
|
||||
|
||||
|
||||
// BSWAP24 of array[3]
|
||||
uint32_t le24toh(uint8_t data[3]) {
|
||||
return (data[2] << 16) | (data[1] << 8) | data[0];
|
||||
}
|
||||
|
||||
// BSWAP24, take u32, output array
|
||||
void htole24(uint32_t val, uint8_t data[3]) {
|
||||
data[0] = (uint8_t) val;
|
||||
data[1] = (uint8_t)(val >> 8);
|
||||
|
|
Loading…
Reference in a new issue