=='3') ret+="0011";
else if (ch[j]=='4') ret+="0100";
else if (ch[j]=='5') ret+="0101";
else if (ch[j]=='6') ret+="0110";
else if (ch[j]=='7') ret+="0111";
else if (ch[j]=='8') ret+="1000";
else if (ch[j]=='9') ret+="1001";
else if (ch[j]=='A'||ch[j]=='a') ret+="1010";
else if (ch[j]=='B'||ch[j]=='b') ret+="1011";
else if (ch[j]=='C'||ch[j]=='c') ret+="1100";
else if (ch[j]=='D'||ch[j]=='d') ret+="1101";
else if (ch[j]=='E'||ch[j]=='e') ret+="1110";
else if (ch[j]=='F'||ch[j]=='f') ret+="1111";
買粉絲ut<<"所得二進制為:";
買粉絲ut<<ret<<endl;
買粉絲ut<<"請按任意鍵返回\n";
getch();
system("cls");
mainmenu();
return 0;
}
int hex_dec()
{
//16->10
買粉絲ut<<"輸入十六進制";
char ch[N];
int b=0,a=0;
cin>>ch;
int i=0,flag=-1;
while(ch[i]!='\0')
{
if(ch[i]=='.')
{
flag=i;
break;
}
i++;
}
i=0;
if(flag==-1)
{ while(ch[i]!='\0')
{
if(ch[i]>='a'&&ch[i]<='f')
b=ch[i]-'a'+10;
else if(ch[i]>='A'&&ch[i]<='F')
b=ch[i]-'A'+10;
else if(ch[i]>='0'&&ch[i]<='9')
b=ch[i]-'0';
a=a*16+b;
i++;
}
買粉絲ut<<a<<endl;
買粉絲ut<<"請按任意鍵返回\n";
getch();
system("cls");
mainmenu();
return 0;
}
double 買粉絲unt=0.0;
double bin=1.0/16;
i=0;
int j;
for(i=0;i<flag;i++)
{ if(ch[i]>='a'&&ch[i]<='f')
b=ch[i]-'a'+10;
else if(ch[i]>='A'&&ch[i]<='F')
b=ch[i]-'A'+10;
else if(ch[i]>='0'&&ch[i]<='9')
b=ch[i]-'0';
a=a*16+b;
}
int d=strlen(ch);
i=flag+1;
for(;i<d;i++)
{ if(ch[i]>='a'&&ch[i]<='f')
b=ch[i]-'a'+10;
else if(ch[i]>='A'&&ch[i]<='F')
b=ch[i]-'A'+10;
else if(ch[i]>='0'&&ch[i]<='9')
b=ch[i]-'0';
買粉絲unt=買粉絲unt+b*bin;
bin/=16.0;
if(j>Q)
break;
}
買粉絲ut<<"轉換后所得對應十進制為:";
買粉絲ut<<setiosflags(ios_base::fixed)<<setprecision(Q)<<(a+買粉絲unt)<<endl; //使用格式化輸出,使其保留Q,6位小數
買粉絲ut<<"請按任意鍵返回\n";
getch();
system("cls");
mainmenu();
return 0;
}
int dec_hex() //十進制到十六進制
{
char b[N];
char ch[N];
string all;
買粉絲ut<<"請輸入待轉換的十進制數:";
cin>>b;
long d=atol(b);
long bb=d;
int i=0,flag=-1;
int j;
while(ch[i]!='\0')
{
if(ch[i]=='.')
{
flag=i;
break;
}
i++;
}
i=0;
while(d!=0)
{ ch[i]=d%16+'0';
d=d/16;
all=ch[i]+all; //加在前面
i++;
}
if(flag==-1)
{ 買粉絲ut<<all<<endl;
買粉絲ut<<"請按任意鍵返回\n";
getch();
system("cls");
mainmenu();
return 0;
}
all=all+".";
double x=atof(b) ;
x=x-(double)bb;
int r=0;
while(1) //乘以16,取整數
{ if((int)(x*16.0)==0)
{
all=all+"0";
x=x*16.0-(int)(x*16.0);
r++;
}
else if((int)(x*16.0)==1)
{
all=all+"1";
x=x*16.0-(int)(x*16.0);
r++;
}
else if((int)(x*16.0)==2)
{
all=all+"2";
x=x*16.0-(int)(x*16.0);
r++;
}
else if((int)(x*16.0)==3)
{
all=all+"3";
x=x*16.0-(int)(x*16.0);
r++;
}
else if((int)(x*16.0)==4)
{
all=all+"4";
x=x*16.0-(int)(x*16.0);
r++;
}
else if((int)(x*16.0)==5)
{
all=all+"5";
x=x*16.0-(int)(x*16.0);
r++;
}
else if((int)(x*16.0)==6)
{
all=all+"6";
x=x*16.0-(int)(x*16.0);
r++;
}
else if((int)(x*16.0)==7)
{
all=all+"7";
x=x*16.0-(int)(x*16.0);
r++;
}
else if((int)(x*16.0)==8)
{
all=all+"8";<
2024-07-04 03:04
2024-07-04 02:11
2024-07-04 02:08
2024-07-04 01:20
2024-07-04 01:07
2024-07-04 00:59