编程问题:16进制出错在哪?只要出错处 - 爱问答

(爱问答)

编程问题:16进制出错在哪?只要出错处

//#include <creation-zero.h>

#include <iostream>

#include <stdio.h>

using namespace std;

char syston10(char c[],int a,int b,int m)

{

int i=0,n=0,l=1;

while(1)

{

if(c[i]==' ')

break;

if(c[i]>='0'&&c[i]<='9')

n+=(c[i]-'0')*l;

if(c[i]>='A'&&c[i]<='Z')

n+=(c[i]-'A'+10)*l;

if(c[i]>='a'&&c[i]<='z')

n+=(c[i]-'a'+10)*l;

i++;

l*=a;

}

int q=0,fuck=n;

while(1)

{

n/=b;

q++;

if(n==0)

break;

}

char p[q];

int u;

for(int z=q-1;z>=0;z++)

{

u=n%b;

n/=b;

if(u>=0&&u<=9)

p[z]=u+'0';

if(u>=10)

p[z]=u-10+'A';

}

if(m<q)

return p[m];

else

return -1;

}

int main()

{

char a[66666];

int m=0;

while(1)

{

scanf("%c",&a[m]);

if(a[m]==' ')

break;

m++;

}

int n=0;

while(1)

{

if(syston10(a,13,18,n)==-1)

break;

cout<<syston10(a,13,18,n);

n++;

}

}


根本没有看明白你的算法,在你的

char syston10(char c[],int a,int b,int m)

中,a/b是常量,分别是13和18.这个与进制转换有关?

另外,既然是常量,又何必作为参数,另外你的m也就是主函数的n值,它也是常量0没有意义

同样在函数中,明明可以直接输入字串(cin及scanf都可以)

你却要用getchar?

程序语法上没有任何错,但算法看上去完成不对

以下是我写的,将一个字串转成2~36进制的函数(我一直用存OJ中的)

void m_itoa( char *buf, int i, unsigned char base)
{
   unsigned int rem;
   unsigned char *s, length = 0;
   s = ( unsigned char *)buf;
   if(i == 0)
       *s++ = '0';
   else
   {
       if(i < 0)
       {
           if(base <= 10)
           {
               *buf++ = '-';
               s =( unsigned char *) buf;
           }
           i = -i;
       }
       while(i)
       {
           ++length;
           rem = i % base;
           if(rem <= 10)
               *s++ = rem + '0';
           else if(base <= 36)
               *s++ =  rem - 10 + 'A';
           i /= base;
       }
       for(base = 0; base < length / 2; base++)
       {
           *(buf + length) = *(buf + base);
           *(buf + base) = *(buf + (length - base - 1));
           *(buf + (length - base - 1)) = *(buf + length);
       }
   }
   *s = 0;
}



假设数据在A2则:B2=CHAR(MOD(J2,8)+LEFT(J2)*8+55-7*(J2%<10.1))&CHAR(MOD(I2,8)+LEFT(I2)*8+55-7*(I2%<10.1))&CHAR(MOD(H2,8)+LEFT(H2)*8+55-7*(H2%<10.1))

下一篇:java用循环语句打印1000~9999中的对称数,对称数如:1221这类型的数字

上一篇:c语言编程非控制台

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?