Any Turbo C programmer out there that are capable of doing this for me :D I cant figure this out :D thank you and God Bless :D

Dani AI

Generated

For (and following 's offer): a compact Turbo C–friendly approach is to read the hex as text, parse it into an unsigned long, print decimal and octal with printf formats, and produce binary with a small bit-walking routine. The sample below accepts input with or without a leading 0x, checks parsing, and avoids signed overflow by using unsigned long.

#include <stdio.h>

void print_binary(unsigned long v) {
    int bits = sizeof(unsigned long) * 8;
    int started = 0;
    int i;
    for (i = bits - 1; i >= 0; --i) {
        unsigned long mask = 1UL << i;
        if (v & mask) {
            putchar('1');
            started = 1;
        } else if (started) {
            putchar('0');
        }
    }
    if (!started) putchar('0');
}

int main(void) {
    char buf[64];
    unsigned long value;
    printf("Enter hex (e.g. 1A3F or 0x1A3F): ");
    if (scanf("%63s", buf) != 1) return 0;
    if (sscanf(buf, "%lx", &value) != 1) {
        puts("Invalid hexadecimal");
        return 0;
    }
    printf("Decimal: %lu\n", value);
    printf("Octal: %lo\n", value);
    printf("Binary: ");
    print_binary(value);
    putchar('\n');
    return 0;
}

Notes: sscanf with %lx accepts an optional 0x/0X prefix; checking its return value validates input. Turbo C often has 16-bit int and 32-bit long—values above 0xFFFFFFFF will overflow an unsigned long. For stronger validation or larger numbers, use strtoul with an end-pointer or parse the string manually. Reference: the strtoul and sscanf behavior is documented at strtoul docs and fscanf/sscanf docs.

Recommended Answers

All 2 Replies

..replied to the third post. Bumping to remove from 'Unanswered'.

Don't get me wrong. If you get stuck writing your program we will help you in any way we can.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.