Created
November 21, 2015 07:02
-
-
Save YieldNull/2f0f11e6b8c7d86a7870 to your computer and use it in GitHub Desktop.
Display memory block via Hexadecimal.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/** | |
* Display memory block via Hexadecimal. | |
* From lower to higher address. | |
**/ | |
void hexOut(unsigned char c) { | |
printf("%x", c & 0xF); | |
printf("%x", (c >> 4) & 0xF); | |
} | |
void displayInHex(void * block, int size) { | |
unsigned char *tmp = (unsigned char *) block; | |
int i; | |
for (i = 0; i < size; i++) { | |
hexOut(*(tmp + i)); | |
if (i % 2 == 1) | |
printf(" "); | |
} | |
printf("\n"); | |
} | |
struct demo { | |
int a; | |
long b; | |
double c; | |
}; | |
int main() { | |
double a = 0.3; | |
struct demo d = { 1, 2, 0.3 }; | |
// double 0.3 in hex is 0x3fd3333333333333 | |
displayInHex(&a, sizeof(a)); //3333 3333 3333 3df3 | |
displayInHex(&d, sizeof(d)); //1000 0000 0000 0000 2000 0000 0000 0000 3333 3333 3333 3df3 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment