Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double d = 1234.5678;
- uint64_t bits;
- memcpy(&bits, &d, sizeof bits);
- printf("the representation of %g is %08"PRIX64"n", d, bits);
- union { double d; uint64_t i; } u;
- u.d = 1234.5678;
- printf("the representation of %g is %08"PRIX64"n", d, u.i);
- void *my_memcpy(void *dst, const void *src, size_t n) {
- unsigned char *d = dst;
- const unsigned char *s = src;
- for (size_t i = 0; i < n; i++) { d[i] = s[i]; }
- return dst;
- }
- double d = 1234.5678;
- void *p = malloc(sizeof(double));
- if (p != NULL) {
- uint64_t *pbits = memcpy(p, &d, sizeof(double));
- uint64_t bits = *pbits;
- printf("the representation of %g is %08"PRIX64"n", d, bits);
- }
- double d = 1234.5678;
- void *p = malloc(sizeof(double));
- assert(p);
- uint64_t *pbits = memcpy(p, &d, sizeof(double));
- uint64_t bits = *pbits;
- printf("the representation of %g is %08"PRIX64"n", d, bits);
- double d = 1234.5678;
- uint64_t bits;
- memcpy(&bits, &d, sizeof bits);
- printf("the representation of %g is %08"PRIX64"n", d, bits);
- double d = 1234.5678;
- uint64_t bits;
- memcpy(&bits, &d, sizeof bits);
- printf("the representation of %g is %08"PRIX64"n", d, bits);
- union { double d; uint64_t i; } u;
- u.d = 1234.5678;
- printf("the representation of %g is %08"PRIX64"n", d, u.i);
- double d = 1234.5678;
- unsigned char bits[sizeof(d)];
- memcpy(&bits, &d, sizeof(bits));
- printf("the representation of %g is ", d);
- for(int i=0; i<sizeof(bits); i++) {
- printf("%02x", (unsigned int) bits[i]);
- }
- printf("n");
Add Comment
Please, Sign In to add comment