Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct x
- {
- int x;
- } __attribute__((packed));
- int main()
- {
- struct x a;
- a.x=127;
- char *b = (char *)&a;
- int i;
- for (i=0; i<4; i++)
- printf("%02x ", b[i]);
- printf("n");
- for (i=0; i<4; i++)
- printf("%d ", b[i]);
- printf("n");
- return 0;
- }
- printf("%02hhx", b[i]);
- for (i=0; i<4; i++)
- printf("%02x ", (unsigned char)b[i]);
- unsigned char *b = (unsigned char *)&a;
- for (i=0; i<4; i++) {
- //...
- }
- for (i=0; i<sizeof(x); i++) {
- //...
- }
Add Comment
Please, Sign In to add comment