do you know a number system conversion code in C?

we need a code in C that converts binary to octal, decimal to hexadecimal and octal to hexadecimal.. :)

Comments

  • #include
    #include

    int main(int argc, char **argv) {
    int n;
    char binary[255];
    int i;

    printf("Enter a number? ");
    scanf("%i", &n);
    printf("%d 0%o 0x%X
    ", n, n, n);

    printf("
    Enter Binary number");
    scanf("%s", binary);
    for (n=0, i=0; i<strlen(binary); i++) {
    n = n*2+(binary[i]-'0');
    }
    printf("%s %d, 0%o, 0x%X
    ", binary, n, n, n);

    return 0;
    }

  • This post has been deleted.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion