Continue to Site

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
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.
 

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
 

YOU CAN MAKE YOUR OWN FUNCTION THERE IS NO STANDARD FUNCTION
 

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top