About My Work

Decimal to Octal, Decimal to Hexa Conversion in Turbo C

Posted by: paolyn lazo on: September 23, 2008

My sister forced me to write a Turbo C program.
Where i the user can do the following:
a. convert a decimal to octal
b. Convert an octal to decimal
c. convert a decimal to hex
d. convert a hex to decimal

After thinking so many things. And formulating a lot of loops, trying to find out if turbo c has midstrig function that can extract each numbers.
Hehehe it seems to me that i complicate things.

This is the output program after reading books on turbo c:

#include<stdio.h>
main()
{

char choice;
int val;

printf(“Please Enter your Choice”);
printf(“(1) Decimal to Octal”);
printf(“(2) Octal to Decimal”);
printf(“(3) Decimal to Hex”);
printf(“(4) Hex to Decimal”);

choice=getche();

case (1):
printf(“Please Enter a decimal value to convert”);
scanf(“%d, &val “);
printf(“The octal value is %o”, val);
break;

case (2):
printf(“Please Enter an octal value to convert”);
scanf(“%o, &val “);
printf(“The decimal value is %d”, val);
break;

case (3):
printf(“Please Enter a decimal value to convert”);
scanf(“%d, &val “);
printf(“The hex value is %x”, val);
break;

case (4):
printf(“Please Enter a hex value to convert”);
scanf(“%x, &val “);
printf(“The octal value is %d”, val);
break;

default:
printf(“Input Error”);

}

i have learned that turbo c has a format converter for printf and scanf. So it is easy to convert to different number system.
Unlike assembly language that you have to control by bits hehehe.

Advertisement

1 Response to "Decimal to Octal, Decimal to Hexa Conversion in Turbo C"

..nice..!!!..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


  • paolynlazo: yeah its for initial migration! Thanks!
  • Naveen: Please notify me when new post added.
  • rnm1978: Be careful with migrating your whole webcat folder. Dashboards and reports that users have created in your destination environment may get overwritten

Categories

Follow

Get every new post delivered to your Inbox.