|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
unsigned char S_box[]={0x7,0x4,0x9,0xc,0xb,0xa,0xd,0x8,0xf,0xe,0x1,0x6,0x0,0x3,0x2,0x5};
有这样一个数组,求解如何将该数组中的值全部取出来连接成为一个然后转换成二进制串?急
这样? #include <stdio.h>
void toBinary(int num, char* bin) {
int n = 0;
while (num) {
bin[n++] = num % 2 ? 1 + '0' : 0 + '0';
num /= 2;
}
char c;
for (int i = 0; i < (n >> 1); ++i) {
c = bin[i];
bin[i] = bin[n - i - 1];
bin[n - i - 1] = c;
}
bin[n] = '\0';
}
int main(void) {
unsigned char S_box[] = { 0x7, 0x4, 0x9, 0xc, 0xb, 0xa, 0xd, 0x8, 0xf, 0xe, 0x1, 0x6, 0x0, 0x3, 0x2, 0x5 };
int N = sizeof(S_box) / sizeof(unsigned char);
char binary[N][32];
for (int i = 0; i < N; ++i) {
toBinary(S_box[i], binary[i]);
}
for (int i = 0; i < N; ++i) {
printf("%s", binary[i]);
}
return 0;
}
1111001001110010111010110110001111111011101110101
|
|