Search
Cílem cvičení je seznámení s učebnou, zopakování základních pojmů na téma reprezentace dat v počítači
Co Vás tento semestr čeká:
Na cvičení budeme vycházet z následujícího programu v C, který budeme dále modifikovat.
Program pro zobrazování reprezentace čísel v paměti:
/* Simple program to examine how are different data types encoded in memory */ #include <stdio.h> /* * The macro determines size of given variable and then * prints individual bytes of the value representation */ #define PRINT_MEM(a) print_mem((unsigned char*)&(a), sizeof(a)) void print_mem(unsigned char *ptr, int size) { int i; printf("address = 0x%016lx\n", (long unsigned int)ptr); for (i = 0; i < size; i++) { printf("0x%02x ", *(ptr+i)); // == printf("0x%02x ", ptr[i]); } printf("\n"); } int main() { /* try for more types: long, float, double, pointer */ unsigned int unsig = 5; int sig = -5; /* Read GNU C Library manual for conversion syntax for other types */ /* https://www.gnu.org/software/libc/manual/html_node/Formatted-Output.html */ printf("value = %d\n", unsig); PRINT_MEM(unsig); printf("\nvalue = %d\n", sig); PRINT_MEM(sig); return 0; }
/opt/apo/binrep/print_binrep
gcc -Wall -pedantic -o print_binrep ./print_binrep.c
Makefile
-14
28-14
28
10-14
10
7*6
-7*6, -7*(-6), 7*(-6)
42/7, 43/7
5,25
0,1
2.5
-31,75
3.67342e-40
%e
printf(“value = %e\n”, a);
float a = 2e38;
float b = 2 * a;
INFINITY
#include <math.h>
float inf = INFINITY;
double x;
31
0