Commit 5b1e3d42 authored by elijah vasquez's avatar elijah vasquez 🦍

commit now hahah

parents
##include <string.h>
##include <stdio.h>
/* Print binary stored in plain 32 bit block */
void intToBinary(unsigned int n)
{
int c, k, i;
printf("How the number is stored in memory ");
for (c = 31; c >= 0; c--)
{
k = n >> c;
// k = n dividedby 2 c times
// or
// take the binary representation of k and move all the digits to the right c times
// since the loop c starts at 31 the first round of the loop moves the left most bit to the units column ( and rottes the rest round)
// we can then use a bitwise and (&) command to compare the righmost digit (previously the leftmost) to 000000000001
// if (k & 1) is true then that bit is 1 otherwise it is zero
// we can then move on to the next loop and look at the second leftmost and so on.
if (k & 1)
printf("1");
else
printf("0");
}
printf(" X * 2 ^ Y\n");
}
int main(void)
{
unsigned int m;
float f = 3.14;
printf("\n\n\nf = %f\n", f);
/* See hex representation */
printf("Float Point Representation of f = %a", f);
printf(" hexadecimal X * 16 ^ Y\n");
/* Copy memory representation of float to plain 32 bit block */
memcpy(&m, &f, sizeof (m));
intToBinary(m);
printf("\n\n\n");
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment