/* AC 17/18 * TPC2 Ex1 */ #include unsigned F2U( float n ) { // float to unsigned int return *(unsigned*)&n; } float U2F( unsigned n ) { // unsigned int to float return *(float*)&n; } void printFloat( float val ) { unsigned int num = F2U( val ); char sign; // should be ' ' or '-' int exponent; float mantissa; if ( val<0 ) sign = '-'; else sign = ' '; exponent = (num>>23) & 0xff; exponent = exponent-127; mantissa = U2F((num & 0x07fffff) | (127<<23)); printf("%c%f x2^%d\n", sign, mantissa, exponent); } int main( int argc, char *argv[] ) { float x; scanf( "%f", &x ); printFloat(x); return 0; } /**************************************************************/ /* AC 17/18 * TPC2 Ex2 */ #include #include void arrayCopy( void *src, void *dst, int elemSize, int num ) { int n = elemSize*num; // num de bytes a copiar char *d = (char*)dst; char *s = (char*)src; if ( src == dst || num == 0 ) return; if ( src < dst && src+n >= dst ) { // ha' overlap s = s+n-1; // copiar de tras para a frente d = d+n-1; while ( n-- >0 ) // podia usar um for. Estude o que este while faz! *d-- = *s--; } else for ( int i=0; i