# How to convert octal to binary using recursion in C?

Page 1 of 1

## 2 Replies - 13675 Views - Last Post: 13 May 2010 - 02:24 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=173340&amp;s=d10f21b23dea4f7463b58ffac5b9d279&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 msharaf

Reputation: 1
• Posts: 12
• Joined: 09-April 10

# How to convert octal to binary using recursion in C?

Posted 12 May 2010 - 10:38 PM

```/* QUESTION 3 */

#include <stdio.h>
#include <conio.h>

void octal (int val, int rem);

int main ()
{
int num;

clrscr ();

printf ("From Decimal: ");
scanf ("%d", &num);

printf ("\nTo Octal: ");

octal (num, num);

getch ();
return (0);
}

void octal (int val, int rem)
{
if (rem == 0)
return;

rem = val % 8;
val = val / 8;

octal (val, rem);

if (rem != 0)
{
printf ("%d", rem);
}
}

```

I have done this so far but now I'm not getting how to convert the octal into binary... Please help me out with code ASAP... All is to be done through recursion...

Regards,

Admin Edit: Please use code tags when posting your code. Code tags are used like so =>

Thanks,
PsychoCoder

Is This A Good Question/Topic? 0

## Replies To: How to convert octal to binary using recursion in C?

### #2 r.stiltskin

• D.I.C Lover

Reputation: 2032
• Posts: 5,435
• Joined: 27-December 05

## Re: How to convert octal to binary using recursion in C?

Posted 12 May 2010 - 11:38 PM

It's actually simpler than what you have done, and only requires 1 parameter (val).

You have to think harder about how the conversion algorithm works. Think about how you would do the conversion with pencil & paper.

### #3 janotte

• code > sword

Reputation: 991
• Posts: 5,141
• Joined: 28-September 06

## Re: How to convert octal to binary using recursion in C?

Posted 13 May 2010 - 02:24 AM

How to do this with pencil and paper is provide at the link here
http://www.dreaminco...5&#entry1015895

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }