answersLogoWhite

0


Best Answer

#include<iostream>

#include<conio.h>

using namespace std;

class conv

{

int x,b,r,arr[20],ch;

public:

void get()

{

cout<<"ENTER THE VALUE TO BE CONVERTED:(IN DECIMAL):";

cin>>x;

cout<<"ENTER BASE TO WHICH U WANT TO CONVERT:(UP TO BASE 18):";

cin>>b;

}

void convert();

};

void conv :: convert()

{

int i=0,j;

cout<<"-----------------CONVERSION PROGRAM------------------------\n";

while(1)

{

cout<<"-----------------------------------------------------------\n";

cout<<"1.CONVERT FROM DECIMAL TO OTHER\n2.QUIT\n";

cout<<"------------------------------------------------------------\n";

cout<<"ENTER UR CHOICE:";

cin>>ch;

switch(ch)

{

case 1:

get();

cout<<"IN BASE "<<b<<":";

while(x>0)

{

r=x%b;

arr[i]=r;

x=x/b;

i++;

}

for(j=i-1;j>=0;j--)

{

if(arr[j]==10)

cout<<"A";

else if(arr[j]==11)

cout<<"B";

else if(arr[j]==12)

cout<<"C";

else if(arr[j]==13)

cout<<"D";

else if(arr[j]==14)

cout<<"E";

else if(arr[j]==15)

cout<<"F";

else if(arr[j]==16)

cout<<"G";

else if(arr[j]==17)

cout<<"H";

else if(arr[j]==18)

cout<<"I";

else

cout<<arr[j];

}

cout<<"\n";

i=0;

break;

case 2:

exit(0);

default:

cout<<"WRONG CHOICE\n";

}

}

}

main()

{

conv obj;

obj.convert();

getch();

return 0;

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: A menu driven program to convert a decimal number to binary octal and hexadecimal?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


What does hexadecimal base 16 convert binary equal?

16 is the 4th power of 2. So a hexadecimal number is converted to binary by replacing each hex digit by the 4-bit binary number having the same value. Conversely, in converting binary to hexadecimal, we group every 4 bits starting at the decimal (binary?) point and replace it with the equivalent hex digit. For example, the hexadecimal number 3F9 in binary is 1111111001, because 3 in binary is 11, F (decimal 15) is 1111, and 9 is 1001.


What is the 4-binary number assoiated with the hexadecimal symbol C?

0xc = 1100 Hexadecimal digits use exactly 4 binary digits (bits). The 0x0 to 0xf of hexadecimal map to 0000 to 1111 of binary. Thinking of the hexadecimal digits as decimal numbers, ie 0x0 to 0x9 are 0 to 9 and 0xa to 0xf are 10 to 15, helps with the conversion to binary: 0xc is 12 decimal which is 8 + 4 &rarr; 1100 in [4 bit] binary.


What is the decimal equivalent of 0XFFFF?

0X at the beginning represent a number in the hexadecimal system of units. FFFF is the hexadecimal equivalent of i) 65535 in decimal system of units ii) 1111111111111111 in binary system of units


Write a program that prints a table of the binary octal and hexadecimal equivalents of the decimal numbers in the range 1 through to 256?

import java.util.Scanner; public class NumberSystem { public void displayConversion() { Scanner input = new Scanner(System.in); System.out.printf("%-20s%-20s%-20s%-20s\n", "Decimal", "Binary", "Octal", "Hexadecimal"); for ( int i = 1; i &lt;= 256; i++ ) { String binary = Integer.toBinaryString(i); String octal = Integer.toOctalString(i); String hexadecimal = Integer.toHexString(i); System.out.format("%-20d%-20s%-20s%-20s\n", i, binary, octal, hexadecimal); } } // returns a string representation of the decimal number in binary public String toBinaryString( int dec ) { String binary = " "; while (dec &gt;= 1 ) { int value = dec % 2; binary = value + binary; dec /= 2; } return binary; } //returns a string representation of the number in octal public String toOctalString( int dec ) { String octal = " "; while ( dec &gt;= 1 ) { int value = dec % 8; octal = value + octal; dec /= 8; } return octal; } public String toHexString( int dec ) { String hexadecimal = " "; while ( dec &gt;= 1 ) { int value = dec % 16; switch (value) { case 10: hexadecimal = "A" + hexadecimal; break; case 11: hexadecimal = "B" + hexadecimal; break; case 12: hexadecimal = "C" + hexadecimal; break; case 13: hexadecimal = "D" + hexadecimal; break; case 14: hexadecimal = "E" + hexadecimal; break; case 15: hexadecimal = "F" + hexadecimal; break; default: hexadecimal = value + hexadecimal; break; } dec /= 16; } return hexadecimal; } public static void main( String args[]) { NumberSystem apps = new NumberSystem(); apps.displayConversion(); } }

Related questions

Convert hexadecimal 4F7B in to binary and decimal?

4F7B: Binary = 100111101111011 Decimal = 20347


Why is Hexadecimal used?

It is used because it is easier to convert to and from binary to hexadecimal than decimal, and it uses less characters than binary. For instance: decimal: 65535 hex: FFFF binary: 1111111111111111


Convert the hexadecimal number 221122 into binary octal and decimal?

221122: Binary = 1000100001000100100010 Octal = 10410442 Decimal = 2232610


Convert 11011001 to decimal?

The answer depends on what you are converting from: binary, ternary, octal, hexadecimal ...


Convert 110001100 into its decimal numbers?

The answer depends on what you are converting from: binary, ternary, octal, hexadecimal ...


Why is it more difficult to convert decimal to hexadecimal?

As compared to converting decimal into what other base! It is no more difficult to convert decimal into base 8 than decimal into binary or Hex.


How do you convert binary to hexadecimal using assembly language?

In order to convert binary to hexadecimal using assembly language, the programmer must possess an understanding on boolean algebra or binary system in other words. A compiler is also needed to complete the program.


How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


What are the decimal and hexadecimal equivalents of the binary number 10011101?

10011101: Decimal = 157 Hexadecimal = 9D


What is decimal binary ocfal and hexadecimal systems?

Decimal is base 10. Binary is base 2. Octal is base 8. Hexadecimal is base 16.


What does hexadecimal base 16 convert binary equal?

16 is the 4th power of 2. So a hexadecimal number is converted to binary by replacing each hex digit by the 4-bit binary number having the same value. Conversely, in converting binary to hexadecimal, we group every 4 bits starting at the decimal (binary?) point and replace it with the equivalent hex digit. For example, the hexadecimal number 3F9 in binary is 1111111001, because 3 in binary is 11, F (decimal 15) is 1111, and 9 is 1001.


Convert 110110.101 to hexadecimal?

Assuming the original was in binary, the answer is 36.A