-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
For
writeups//Misc/How-float-value-store-in-memory.md
Lines 114 to 136 in e58e4bb
| ## Lets Confirm it through program | |
| ``` | |
| #include <stdio.h> | |
| void main() | |
| { | |
| float f; | |
| f = 13.37; | |
| printf("address of f : %p\n", &f); | |
| } | |
| ``` | |
| ### In GDB | |
| ``` | |
| address of f : 0x7fffffffdda4 | |
| ... | |
| pwndbg> x/xw 0x7fffffffdda4 | |
| 0x7fffffffdda4: 0x4155eb85 | |
| ``` |
Instead of using gdb to print it as hex another option is to use it as such
#include <stdint.h>
#include <stdio.h>
typedef union {
uint32_t integer;
float decimal;
} pack;
int main(int argc, char **argv) {
pack me;
me.decimal = 13.37;
printf("0x%x\n", me.integer);
return 0;
}or
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
uint32_t *int_ptr;
float *float_ptr = (float *)malloc(sizeof(float));
int_ptr = float_ptr;
*float_ptr = 13.37;
printf("0x%x\n", *int_ptr);
free(float_ptr);
return 0;
}Metadata
Metadata
Assignees
Labels
No labels