9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
guia07/ex05.c (560B)
   1 #include <stdio.h>
   2 #include <stdlib.h>
   3 
   4 #define MASK_BYTE 0xFF
   5 
   6 int main(void) {
   7 
   8     /* 0x10 30 25 F4 */
   9     unsigned int n = 271590900;
  10 
  11     /* Arreglo de 4 bytes; */
  12     unsigned char x[4]; 
  13 
  14     size_t i;
  15 /*
  16     x[0] = (n >> 24) & 0xFF;
  17     x[1] = (n >> 16) & 0xFF;
  18     x[2] = (n >> 8) & 0xFF;
  19     x[3] = (n >> 0) & 0xFF;
  20 */
  21     for(i = 0; i < sizeof(unsigned int); i++)
  22         x[i] = (n >> ( (sizeof(unsigned int) - 1 - i) * 8  )) & MASK_BYTE;
  23 
  24     printf("%d\n", n);
  25     printf("%X\n", n);
  26 
  27     for(i = 0; i < sizeof(unsigned int); i++)
  28         printf("x[%lu] = %X\n", i, x[i]);
  29 
  30     return EXIT_SUCCESS;
  31 }