Created
August 30, 2023 09:47
-
-
Save fischerbach/16a8d51eedf522c6e80615e39d4370e5 to your computer and use it in GitHub Desktop.
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> | |
int main() { | |
float f = 1234.5678f; | |
union { | |
float f; | |
unsigned char b[4]; | |
} my_f; | |
my_f.f = f; | |
printf("float: %f\n", my_f.f); | |
printf("bytes: %.2x %.2x %.2x %.2x\n", | |
my_f.b[3], my_f.b[2], my_f.b[1], my_f.b[0]); | |
my_f.b[3] |= 0x80; //0x80 == binary 1000 0000 | |
printf("float: %f\n", my_f.f); //should return negative value | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment