Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help me with C++ programming

Status
Not open for further replies.

armess

Member level 3
Joined
Sep 22, 2006
Messages
64
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,692
Hai,
can somebody help me with the C++ program of converting a decimal no into its hexadecimal form.
If possible plz send the code.
 

Lucifre

Full Member level 2
Joined
Jul 5, 2005
Messages
126
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,296
Location
Detroit MI
Activity points
2,400
here is the code:

Code:
#include <iostream>
using namespace std;

int main(){
    int userinputdec;  
    cout << "Please enter a number in decimal: ";
    cin >> userinputdec;
    cin.ignore();
    cout << "The number in hex is: ";
    cout << hex << uppercase << userinputdec << endl;
    cout << "enter 1 to exit and any other key to continue: " ;
    cin >> selection;
    cin.ignore();   
}
if this is what you're looking for

Added after 2 minutes:

OOOOPS sorry wrong code
i meant
Code:
int main(){
    int userinputdec;  
    cout << "Please enter a number in decimal: ";
    cin >> userinputdec;
    cin.ignore();
    cout << "The number in hex is: ";
    cout << hex << uppercase << userinputdec << endl;        
    cin.get();   
}
sorry bout that
 

shabab

Member level 3
Joined
Apr 3, 2007
Messages
58
Helped
3
Reputation
6
Reaction score
0
Trophy points
1,286
Activity points
1,537
YOU CAN MAKE YOUR OWN FUNCTION THERE IS NO STANDARD FUNCTION
 

tjr

Member level 3
Joined
Mar 2, 2006
Messages
60
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,674
void findhex(int num)
{
int d,i=0,val;
char hex[6];
while(num)
{
d=num%16;
if(d>=10&&d<=15)
{ val=d-10;
if(val>=0)
hex=65+val;
}
i++;
num=num/16;
}
hex='\0';
strrev(hex);
printf("Hexa num: %s",hex);
}


here findhex() is user defined function
strrev() is std library function defined in "string.h"
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top