Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- #define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c"
- #define BYTE_TO_BINARY(byte) \
- (byte & 0x80 ? '1' : '0'), \
- (byte & 0x40 ? '1' : '0'), \
- (byte & 0x20 ? '1' : '0'), \
- (byte & 0x10 ? '1' : '0'), \
- (byte & 0x08 ? '1' : '0'), \
- (byte & 0x04 ? '1' : '0'), \
- (byte & 0x02 ? '1' : '0'), \
- (byte & 0x01 ? '1' : '0')
- //--------------------------------------------------------------
- uint8_t scratch[16] = {
- 0xFF, 0x00, 0x00, 0xFF,
- 0x00, 0xFF, 0x00, 0x00,
- 0x00, 0x00, 0xFF, 0x00,
- 0xFF, 0x00, 0x00, 0x00,
- };
- int main()
- {
- uint16_t tt = 0;
- for(int i = 0; i < 16; i++) {
- if (scratch[i] == 0xFF)
- tt = (tt>>1) | 0x8000;
- else
- tt = tt>>1;
- printf("i=%02d (0x%02X) tt=0x%04X " BYTE_TO_BINARY_PATTERN BYTE_TO_BINARY_PATTERN "\n",
- i,
- scratch[i],
- tt,
- BYTE_TO_BINARY(((tt>>8) & 0xFF)),
- BYTE_TO_BINARY(((tt) & 0xFF)));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement