diff options
author | tmk <nobody@nowhere> | 2013-05-14 16:16:57 +0900 |
---|---|---|
committer | tmk <nobody@nowhere> | 2013-05-14 16:16:57 +0900 |
commit | d9c06db60006e2191d8b86e34f651644a54426b4 (patch) | |
tree | 14b79372b1d0f0d9623b21e6dbffa73ce2036b7f /common/util.c | |
parent | b9f558b3d89fc434d6dab348698d5100ff82d16b (diff) | |
download | qmk_firmware-d9c06db60006e2191d8b86e34f651644a54426b4.tar.gz |
Add xprintf(xitoa) from elm-chan.org
Diffstat (limited to 'common/util.c')
-rw-r--r-- | common/util.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c index 6d4d6bfda..7e0d54299 100644 --- a/common/util.c +++ b/common/util.c @@ -77,3 +77,25 @@ uint8_t biton32(uint32_t bits) if (bits >> 1) { bits >>= 1; n += 1;} return n; } + + + +uint8_t bitrev(uint8_t bits) +{ + bits = (bits & 0x0f)<<4 | (bits & 0xf0)>>4; + bits = (bits & 0b00110011)<<2 | (bits & 0b11001100)>>2; + bits = (bits & 0b01010101)<<1 | (bits & 0b10101010)>>1; + return bits; +} + +uint16_t bitrev16(uint16_t bits) +{ + bits = bitrev(bits & 0x00ff)<<8 | bitrev((bits & 0xff00)>>8); + return bits; +} + +uint32_t bitrev32(uint32_t bits) +{ + bits = (uint32_t)bitrev16(bits & 0x0000ffff)<<16 | bitrev16((bits & 0xffff0000)>>16); + return bits; +} |