A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to convert number from Octal to Decimal
Q:

C program to convert number from Octal to Decimal

0

C program to convert number from Octal to Decimal

In this program, we will read Octal Values and converts it into Hexadecimal Number System. This program is for Octal to Decimal Conversion in C.

The logic behind to implement this program - Access each digit from the Number multiply the digit by the power of 8 (for first digits from right side multiply digit with 8^0, second digits 8^1 and so on), add the result and finally you will get Decimal value of given Octal Number. Here we will multiply with the power of base and base of Octal Number is 8.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Octal to Decimal Conversion using C program

/*C program to convert number from octal to decimal*/

#include <stdio.h>
#include <string.h>
#include <math.h>

int main()
{
    char oct[32] = { 0 };
    int dec, i;
    int cnt; /*for power index*/

    printf("Enter octal value: ");
    gets(oct);

    cnt = 0;
    dec = 0;
    for (i = (strlen(oct) - 1); i >= 0; i--) {
        dec = dec + (oct[i] - 0x30) * pow((double)8, (double)cnt);
        cnt++;
    }

    printf("DECIMAL value is: %d", dec);

    return 0;
}

Output:

    Enter octal value: 1041
    DECIMAL value is: 545

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now