Advertisement
J00ker

Untitled

Oct 18th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. void PrintBiti(int n) {
  8.     int b = sizeof(n) * 8;
  9.     for(int i = b-1; i >= 0; i--)
  10.         printf("%d", ((n >> i) & 1));
  11. }
  12.  
  13. int main()
  14. {
  15.     /*
  16.     int n, x;
  17.  
  18.     printf("n = ");
  19.     scanf("%d", &n);
  20.  
  21.     printf("%d\n", n << 3);
  22.     printf("%d\n", n >> 2);
  23.     printf("%d\n", (n << 3) + (n << 1));
  24.     */
  25.  
  26.     /// LAB. 2
  27.  
  28.     /// 1
  29.     /*
  30.     int b = sizeof(n) * 8;
  31.     for(int i = b-1; i >= 0; i--) {
  32.         if(n & (1 << i)) printf("%d", 1);
  33.         else printf("%d", 0);
  34.     }
  35.  
  36.     printf("\n");
  37.     for(int i = b-1; i >= 0; i--)
  38.         printf("%d", ((n >> i) & 1));
  39.  
  40.     */
  41.     /// 2
  42.     /*
  43.     printf("\n\nx = ");
  44.     scanf("%d", &x);
  45.  
  46.     int aux;
  47.     aux = ((x >> (n - 1)) & 1);
  48.     printf("%d\t", aux);
  49.     PrintBiti(aux);
  50.     printf("\n");
  51.  
  52.     aux = ((x | (1 << (n - 1))));
  53.     printf("%d\t", aux);
  54.     PrintBiti(aux);
  55.     printf("\n");
  56.  
  57.     aux = ((x & (255 - (1 << (n - 1)))));
  58.     printf("%d\t", aux);
  59.     PrintBiti(aux);
  60.     printf("\n");
  61.  
  62.     aux = ((x ^ (1 << (n - 1))));
  63.     printf("%d\t", aux);
  64.     PrintBiti(aux);
  65.     */
  66.     /// 3
  67.     /*
  68.     int x, y, n, p;
  69.     printf("x = "); scanf("%d", &x);
  70.     printf("y = "); scanf("%d", &y);
  71.     printf("n = "); scanf("%d", &n);
  72.     printf("p = "); scanf("%d", &p);
  73.  
  74.     printf("\ny = \t");
  75.     PrintBiti(y);
  76.     y = (y & ((1 << n) - 1));
  77.     printf("\ny = \t");
  78.     PrintBiti(y);
  79.  
  80.     y = y << p;
  81.     printf("\ny = \t");
  82.     PrintBiti(y);
  83.  
  84.     printf("\nx = \t");
  85.     PrintBiti(x);
  86.  
  87.     int aux = ((1 << n) - 1) << p;
  88.     printf("\naux = \t");
  89.     PrintBiti(aux);
  90.  
  91.  
  92.     x = x & ~aux;
  93.     printf("\nx = \t");
  94.     PrintBiti(x);
  95.  
  96.     x = x | y;
  97.     printf("\nx = \t");
  98.     PrintBiti(x);
  99.     */
  100.  
  101.     /// 4
  102.     char n[10];
  103.     printf("n = "); scanf("%d", &n);
  104.  
  105.     char Conv[16][5] = {
  106.         "0000",
  107.         "0001",
  108.         "0010",
  109.         "0011",
  110.         "0100",
  111.         "0101",
  112.         "0110",
  113.         "0111",
  114.         "1000",
  115.         "1001",
  116.         "1010",
  117.         "1011",
  118.         "1100",
  119.         "1101",
  120.         "1110",
  121.         "1111"
  122.     };
  123.  
  124.     int len = strlen(n);
  125.     for(int i = 0; i < len; i++) {
  126.         if(i >= 0 && i <= 9)
  127.             printf(Conv[i]);
  128.         else
  129.             printf(Conv[i + n[i] - 'A' + 1]);
  130.     }
  131.  
  132.  
  133.  
  134.     return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement