the function converts the first parameter into a string containing the hexadecimal equivalent of the number
function that accepts 2 parameters an unsigened char and a pointer to character
Collapse
X
-
Tags: None
-
iam a student and i am beginner in programming but i can not understand how to change a char into a string -
and also how the string containing the hexadecimal equivalent of the number
what i know is that strings is an arrau of characterComment
-
Code://A string is a series of characters. string s="This is my hex number - 0xff"; cout<<s; //prints--> This is my hex number - 0xff cout<<dec<<0xff; // prints 255 /*Or you can use a container like an array so that each array element from 0 up contains each character from the first onwards.*/ char a[]={'0','x',1,2,3,4,'/0'}; //initialize a 7 element //array with a hex number for(int i=0;i<6;i++) //traverse array and print its individual // elements cout<<a[i];//prints 0x1234 cout<<dec<<0x1234; // prints 4660 //hope this helps.Comment
-
I see.....you wish to write a function which converts an integer (in hexadecimal format) into a string?.....yes ?
If so consider the following.
int hex_num=0;
cout<<"enter an integer in hex format";
cin>>hex_num; //say 0x1234 is entered
string convert_hex_to_ string(hex_num) //conversion function of type string
{
string s=hex_num; //now s contains the string " 0x1234"
return s;
}
cout<<s;//prints 0x1234
Is that what you are trying to do.....or is it something else entirely?Comment
Comment