作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了下面的代码来将八进制数转换为十六进制数:
int main()
{
int octal[100]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int binary[100]={0, 1, 10, 11, 100, 101, 110, 111, 1000,1001, 1010, 1011, 1100, 1101, 1110, 1111};
int Hinary[100]={0, 1, 10, 11, 100, 101, 110, 111, 1000,1001, 1010, 1011, 1100, 1101, 1110, 1111};
long long tempoctal,last1,binar,hocatl,place=1;
long long i,tempbinary,last2,index;
char hexadecimal[100];
index=0;
binar=0;
printf("enter an octal number: ");
scanf("%lld",&hocatl);
tempoctal=hocatl;
while(tempoctal != 0){
last1=tempoctal%10;
binar=(binary[last1] * place) + binar;
place *= 1000;
tempoctal /=10;
}
tempbinary=binar;
printf("this is the number: %lld",tempbinary);
while(tempbinary != 0){
last2=tempbinary%10000;
for(i=0 ; i<16 ; i++){
if(Hinary[i] == last2){
if(i<10){ hexadecimal[index]= i + '0'; }
else{ hexadecimal[index]= (i-10) + 'A' ; }
}
}
index++;
tempbinary /=10000;
}
hexadecimal[index]= '\O';
strrev(hexadecimal);
printf("\nthis is the hex: %s",hexadecimal);
问题是程序可以工作,但在每个十六进制输出中,十六进制数字之前都有一个零,我不知道为什么。
最佳答案
我认为它的出现是因为
if(i<10){ hexadecimal[index]= i + '0'; }
要解决零问题,您可以在打印之前使用它:
if (hexadecimal[0] == '0')
{
hexadecimal++;
}
此外,正如 Rup 所说,在注释中,您使用 Oliver 的“\O”,而不是“\0”,在这里:
hexadecimal[index]= '\O';
关于将八进制转换为十六进制的 C 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58077993/
谁能推荐一个好的成员(member)结构? 例如,用户支付了 1 个月的成员(member)费,从 2012 年 2 月 1 日到 2012 年 3 月 1 日结束。 何时何地检查用户是否仍是成员(m
我想在我的 JTextPane 中实现查找机制(如文本编辑器或 word)。我希望它有下一个/上一个选项(向上/向下箭头)并突出显示它找到的所有单词。有没有简单的方法可以做到这一点? 最佳答案 我不是
Android 上是否有任何机制和/或编程实践来执行一次性安装/更新脚本?这似乎是一个非常基本的问题,但谷歌搜索没有帮助。 假设我的应用程序使用了一个数据库,并且需要一个常量值表(例如国家名称、城市名
是否可以将 SimpleMembership 与 ASP.NET WebForms 一起使用? John Galloway 的文章似乎表明 WebForms“在 ASP.NET 成员资格之上实现 OA
我是一名优秀的程序员,十分优秀!