相关疑难解决方法(0)

c中的二进制到十进制

我有一个简单的代码将二进制数转换为十进制数.在我的编译器中,分解对于小于1000的数字来说效果很好,超出输出总是相同的1023.任何人都有一个想法?

#include <stdio.h>
#include <stdlib.h>

// how many power of ten is there in a number 
// (I don't use the pow() function to avoid trouble with floating numbers)
int residu(int N)
{
    int i=0;
    while(N>=1){
        N=N/10;
        i++;
    }
    return i;
}

//exponentiating a number a by a number b
int power(int a, int b){
    int i;
    int res=1;
    for (i=0;i<b;i++){res=a*res;}
    return res;
}

//converting a number N
int main()
{
    int i;

    //the number to convert
    int N;
    scanf("%d",&N); …
Run Code Online (Sandbox Code Playgroud)

c binary

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

binary ×1

c ×1