반응형
#include<stdio.h>
#pragma warning(disable:4996)
int main() {
char Cnum_1;
char Cnum_2;
int i, j;
int result_1[20];
int result_2[20];
result_1[7] = 0;
result_2[7] = 0;
int count_a1 = 0, count_a2 = 0, count_b1 = 0, count_b2 = 0;
printf("Cnum_1,Cnum_2입력: ");
scanf("%c %c",&Cnum_1,&Cnum_2);
printf("Cnum_1:%d\nCnum_2:%d\n", Cnum_1, Cnum_2);
int num_1 = Cnum_1;
int num_2 = Cnum_2;
for (i = 0; num_1 > 0; i++) {
result_1[i] = num_1 % 2;
result_2[i] = num_2 % 2;
num_1 = num_1 / 2;
num_2 = num_2 / 2;
}
printf("");
for (j = i ; j >= 0; j--) {
printf("%d",result_2[j]);
}
printf(" ");
for (j = i ; j >= 0; j--) {
printf("%d", result_1[j]);
}
printf("\n");
for (i = 7; i >= 0; i--) {
if (i < 4) {
if (result_1[i] == 1) count_a1++;
}
if (i > 3) {
if (result_1[i] == 1) count_a2++;
}
}
for (i = 7; i >= 0; i--) {
if (i < 4) {
if (result_2[i] == 1) count_b1++;
}
if (i > 3) {
if (result_2[i] == 1) count_b2++;
}
}
for (j = 7; j >= 0; j--) {
if (j < 4) {
printf("%d", result_2[j]);
if (j == 0) printf("(%d)", count_b2 % 2);
}
if (j > 3) {
printf("%d", result_2[j]);
if (j == 4) printf("(%d)", count_b1 % 2);
}
}
for (j = 7; j >= 0; j--) {
if (j < 4) {
printf("%d", result_1[j]);
if (j == 0) printf("(%d)", count_a2 % 2);
}
if (j > 3) {
printf("%d", result_1[j]);
if (j == 4) printf("(%d)", count_a1 % 2);
}
}
return 0;
}
반응형
'Network' 카테고리의 다른 글
[Network]ICMPv6 (0) | 2024.03.12 |
---|---|
[C Network Programming] Dijkstra's Routing Algorithm C code (0) | 2024.03.11 |
[C Network Programming] Stop&Wait ARQ Protocol (0) | 2024.03.10 |
[C Network Programming] Distance Vector Routing Algorithm C code (0) | 2024.03.10 |