Created
February 10, 2013 09:39
-
-
Save mmitou/4748983 to your computer and use it in GitHub Desktop.
文字をダンプ
This file contains hidden or 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> | |
| void dump_char(const char c) { | |
| size_t i = 0; | |
| char buf[8] = {0}; | |
| for(i = 0; i < 8; ++i) { | |
| buf[7-i] = ((c >> i) & 0x01); | |
| } | |
| for(i = 0; i < 8; ++i) { | |
| printf("%d", buf[i]); | |
| } | |
| } | |
| void dump(void *p, size_t size) { | |
| char *q = (char *) p; | |
| size_t i; | |
| for(i = 0; i < size; ++i) { | |
| size_t j = size - i - 1; | |
| char c = q[j]; | |
| dump_char(c); | |
| printf(" "); | |
| } | |
| } | |
| int main() | |
| { | |
| int x = 0x01; | |
| double y0 = 0.1; | |
| double y1 = -0.1; | |
| dump(&x, sizeof(x)); | |
| printf("\n"); | |
| dump(&y0, sizeof(double)); | |
| printf("\n"); | |
| dump(&y1, sizeof(double)); | |
| printf("\n"); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment