Thread: Hi there I'm new beginner. Decimal/Octal converter help/

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2022
    Posts
    2

    Hi there I'm new beginner. Decimal/Octal converter help/

    I downloaded this code from some site after a search. As you can see it has a limit(295600127). Why? is there a mistake in the code. . anyways I want to make it work correctly. With someones help of course. Basically explail what is going on below the first return 0;

    Code:
    /*295600127currentlimit*/
    
    
    
    #include <stdio.h>
    #include <math.h>
    
    
    
    
    int convertDecimalToOctal(int decimalNumber);
    int main()
    {
    int decimalNumber;
    
    
    
    
    printf("Enter a decimal number: ");
    scanf("%d", &decimalNumber);
    
    
    
    
    printf("%d in decimal = %d in octal", decimalNumber, convertDecimalToOctal(decimalNumber));
    
    
    
    
    return 0;
    }
    
    
    
    
    int convertDecimalToOctal(int decimalNumber)
    {
    int octalNumber = 0, i = 1;
    
    
    
    
    while (decimalNumber != 0)
    {
    
    
    octalNumber += (decimalNumber % 8) * i;
    decimalNumber /= 8;
    i *= 10;
    }
    
    
    
    
    return octalNumber;
    }
    Just to prove i'm a beginner this is my own dec/oct converter:
    It would only do up 2147483647 until I figured out to unsign my int's
    I guess I can't wordwrap my code huh?

    Code:
    /*decimal_octal_converter*/
    
    
    
    #include <stdio.h>
    /*---------------*/
    
    
    
    
    unsigned int dec, oct;
    
    
    
    
    int main(void)
    
    
    
    
    {
    printf("Enter a number between 0 and 4294967295: ");
    scanf ("%d", &dec);
    
    
    
    
    
    
    
    
    printf("Octal value: %d%d%d%d%d%d%d%d%d%d%d", dec/(8*8*8*8*8*8*8*8*8*8), dec%(8*8*8*8*8*8*8*8*8*8)/(8*8*8*8*8*8*8*8*8), dec%(8*8*8*8*8*8*8*8*8)/(8*8*8*8*8*8*8*8), dec%(8*8*8*8*8*8*8*8)/(8*8*8*8*8*8*8), dec%(8*8*8*8*8*8*8)/(8*8*8*8*8*8), dec%(8*8*8*8*8*8)/(8*8*8*8*8), dec%(8*8*8*8*8)/(8*8*8*8), dec%(8*8*8*8)/(8*8*8), dec%(8*8*8)/(8*8), dec%(8*8*8)%(8*8)/8, dec%8);
    
    
    
    
    return 0;
    }



    And this is the easiest one:
    It took me a while to learn that %o means substitute the decimal number with it's equivalent octal value. In fact if yoy replace the o with an x it wil give the hex value. I couldn't figure out how just modulus%ozero could do all that figuring. Obviously I now know that's not a zero but an "o".

    Code:
    /* C Program to Convert Decimal to Octal Number */
    
    
    
    #include <stdio.h>
    int main()
    {
    int number;
    printf("\n Please Enter the Number You want to Convert : ");
    scanf("%d", &number);
    
    
    
    
    printf("\n Octal Number of a Given Number = %o", number);
    
    
    
    
    return 0;
    }
    Last edited by ManyBeers; 09-05-2022 at 10:33 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [BEGINNER] Binary To Decimal Converter Help
    By Sankait Laroiya in forum C Programming
    Replies: 15
    Last Post: 09-17-2014, 07:21 AM
  2. [BEGINNER] Decimal to Binary Converter help
    By Sankait Laroiya in forum C Programming
    Replies: 7
    Last Post: 09-11-2014, 10:10 AM
  3. Converting Octal to decimal
    By lavaboy in forum C Programming
    Replies: 26
    Last Post: 03-21-2014, 07:11 PM
  4. Decimal, Octal & Hexadecimal
    By mie2cpr in forum C Programming
    Replies: 2
    Last Post: 03-01-2011, 10:56 AM
  5. Decimal to Hex Converter
    By rocketman03 in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:50 AM

Tags for this Thread