Skip to content

Instantly share code, notes, and snippets.

@gabriel-v
Last active November 2, 2015 16:43
Show Gist options
  • Save gabriel-v/f4a3943efdd74916ec17 to your computer and use it in GitHub Desktop.
Save gabriel-v/f4a3943efdd74916ec17 to your computer and use it in GitHub Desktop.
/**
* Autor: Gabriel V. - 312CC
* 2 noiembrie 2015
* Pentru partialul de la PL cu domnul profesor S. Petrescu.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define print_size(type) printf("sizeof %s \t= %ld bits\n", #type, sizeof(type)*8)
int main() {
srand(time(NULL));
int n3 = rand() % (2 << 19) - (2 << 18);
int n4 = 2 << (rand() % 9);
int t;
float x = (float) n3 / n4;
short n1 = rand(), n2 = rand();
print_size(int);
print_size(short);
print_size(float);
printf(" 1. N1 = %d, N2 = %d. Treci in hex si aduna-le, tot in hex.\n", n1, n2);
printf(" 2. X = %f. Gaseste imaginea IEEE-754, in hex.\n", x);
t = time(NULL);
getchar();
printf("1R: N1 = %hX, N2 = %hX, N1 + N2 = %hX.\n", n1, n2, n1 + n2);
printf("2R. X = %X.\n", *((int*) &x));
t = time(NULL) - t;
printf("Ti-a luat %d minute si %d secunde\n", t / 60, t % 60);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment