#include<stdio.h>
int main()
{
int input = 0;
int binaryNumber = 0;
int decimalNumber = 0;
int remainder = 0;
int i = 1;
int wholeNumber = 0;\
int number = 0;
char hexLetters[] = "ABCDEF";
printf("Press 1 to convert Binary to Hex\n");
printf("Press 2 to convert Hex to Binary\n");
printf("Press 3 to convert Decimal to 2's to Compliment Binary\n");
scanf("%d",&input);
printf("\n");
switch (input)
{
case 1:
{
printf("Enter a Binary number\n");
scanf("%d",&binaryNumber);
char binaryToHex[2];
while(binaryNumber != 0)
{
remainder = binaryNumber%10;
decimalNumber = decimalNumber + (remainder*i);
i = i*2;
binaryNumber = binaryNumber/10;
}
while(decimalNumber != 0)
{
remainder = decimalNumber%16;
wholeNumber = (decimalNumber%16)-(remainder/16);
decimalNumber = 0;
}
int j = 1;
for(j=1;j<16;j++){
if(remainder ==j){
binaryToHex[1] = hexLetters[j-10];
}
else{
binaryToHex[1] = remainder;
}
}
int k = 1;
for(k=1;k<16;k++){
if(wholeNumber == k){
binaryToHex[0] = hexLetters[k-10];
}
else{
binaryToHex[0] = wholeNumber;
}
}
printf("%c%c\n", binaryToHex[0], binaryToHex[1]);
请帮助什么都不会显示,经过一些修补后只有 F 会显示这是
错误的。我已经检查以确保余数和整数都在工作并且它确实得到了正确的数字但是当我尝试将一个字母存储到 binaryToHex 时它总是 F 或者它什么都没有。请帮忙