Guest User

Untitled

a guest
Feb 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.20 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define MASK1 1
  5. #define MASK2 3
  6. #define MASK4 15
  7. #define MASK11 2047
  8.  
  9. void mostrar_representacion(int, int);
  10.  
  11.  
  12. int main(int argc, char *argv[]){
  13.  
  14.   struct mptres{
  15.  
  16.       unsigned enfasis :2;
  17.       unsigned original :1;
  18.       unsigned copyright :1;
  19.       unsigned extension_mode :2;
  20.       unsigned channel_mode :2;
  21.       unsigned bit_privado :1;
  22.       unsigned padding_bit :1;
  23.       unsigned tasa_muestreo :2;
  24.       unsigned bitrate_index :4;
  25.       unsigned proteccion :1;
  26.       unsigned layer :2;
  27.       unsigned version :2;
  28.       unsigned frame_sync :11;
  29.  
  30.   }header;
  31.  
  32.  
  33.   FILE *ptr;
  34.   int i = 0;
  35.   int encontrado = 0;
  36.  
  37.   ptr = fopen("/home/desing/Música/06 - Full Focus.mp3","r");
  38.  
  39.       while (!encontrado) {
  40.  
  41.          fseek(ptr, i, SEEK_SET);
  42.          fread(&header, sizeof(int), 1, ptr);
  43.  
  44.          if(header.frame_sync == MASK11)
  45.             encontrado = 1;
  46.  
  47.          i++;
  48.  
  49.     }
  50.  
  51.     printf("bits de sync:");
  52.     mostrar_representacion (header.frame_sync, 11);
  53.  
  54.     printf("bits de version:");
  55.     mostrar_representacion(header.version, 2);
  56.  
  57.     printf("bits de layer:");
  58.     mostrar_representacion(header.layer, 2);
  59.  
  60.     printf("bit de proteccion:");
  61.     mostrar_representacion(header.proteccion, 1);
  62.  
  63.     printf("bits de bitrate index:");
  64.     mostrar_representacion(header.bitrate_index, 4);
  65.  
  66.     printf("bits de tasa de muestreo:");
  67.     mostrar_representacion(header.tasa_muestreo, 2);
  68.  
  69.     printf("bit de padding:");
  70.     mostrar_representacion(header.padding_bit, 1);
  71.  
  72.     printf("bit privado:");
  73.     mostrar_representacion(header.bit_privado, 1);
  74.  
  75.     printf("bits de channel mode:");
  76.     mostrar_representacion(header.channel_mode, 2);
  77.  
  78.     printf("bits de extension mode:");
  79.     mostrar_representacion(header.extension_mode, 2);
  80.  
  81.     printf("bit de copyright:");
  82.     mostrar_representacion(header.copyright, 1);
  83.  
  84.     printf("bit de original:");
  85.     mostrar_representacion(header.original, 1);
  86.  
  87.     printf("bits de enfasis:");
  88.     mostrar_representacion(header.enfasis, 2);
  89.  
  90.     return EXIT_SUCCESS;
  91.  
  92. }
  93.  
  94.  
  95. void mostrar_representacion(int c, int k){
  96.  
  97.     int i;
  98.  
  99.     for(i = k - 1; i>=0; i--){
  100.  
  101.         if((c >> i) & 1)
  102.             printf("1");
  103.         else
  104.             printf("0");
  105.  
  106.     }
  107.  
  108.     printf("\n");
  109.  
  110. }
Add Comment
Please, Sign In to add comment