1. 将一个数转为二进制 ( 一共8位),交换前后4位,得到新生成的数:
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
int revert_binary(int a)
{
int b = ((a & 0x0F) << 4) | ((a & 0xF0) >> 4);
return b;
}
int main() {
//code
int a, tmp;
cin >> a;
while(a--)
{
cin >> tmp;
// change tmp to binary
// swap
// change binary to result
cout << revert_binary(tmp) << endl;
}
return 0;
}