2 Replies - 10234 Views - Last Post: 13 May 2010 - 02:24 AM Rate Topic: -----

#1 msharaf  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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,
Linkpedia's Admin
www.linkpedia.co.nr

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

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

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

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1