Click to See Complete Forum and Search --> : converting characters in my dialog box into Ascii,Hex and Decimal


stephenwhite
November 1st, 1999, 11:35 AM
ive created a dialog box with 4 edit boxes and 3 button controls
the top edit box (IDC_CHARACTER)m_strChar is where you input the data and the you choose one of the button boxes ( ascii , hex,decimal) . ive created and check it , then i want my CCharacterDlg::OnCalculate function to right 3 if , statements to see if which button box is crossed and then to implement the math to change the data accordingly ie
if
On_Bhex_button_crossed
then m_strChar = Hex so.....
convert characters into ascii and decimal.
and so on for ascii , decimal , hex.
any ideas...?????
someone ...
anyone.....lol
thanks guy's any code would be appreciated.
steve

amir meshy
November 2nd, 1999, 08:49 AM
Sorry, your question is vague...
If you need to convert from ascii to decimal - just cast the parameter into unsigned int.
To display either in ascii, decimal or hex, use the CString::Format().. which takes parameters just like sprintf().
Then display this CString in your edit box.
%x is for hex, %d for decimal, %s for strings...

Hope I was helpful..

Amir Meshy, Software Engineer
eci Telecom

stephenwhite
November 2nd, 1999, 09:14 AM
hi amir,
thanks for your mail..
ive created a dialog box that will accept characters in IDC_CHARACTER(m_strChar),

ive got 3 radio buttons which the user will tick once they have put the characters in the IDC_CHARACTER box to show what type of character they are inputting ie Ascii , Hex or Decimal

it then should accept the characters in the box as being either Ascii or Hex or Decimal depending on which button has been checked
and then do a converstion to change the charcters in the box into either Ascii or Hex or decimal depending on which converstions need to be done

and then output the results in IDC_HEX and IDC_DECIMAL and IDC_ASCII
ive managed to do the code for the ascii button being ticked ie the characters in IDC_CHARACTER are ASCII so convert to Hex and Decimal
just cant figure out code to convert characters if the user has input Hex or Decimal characters

and most frustratingly i cant figure out how then to write the converstion to the IDC_("edit boxes")

cor thats confused me what about you ?
its giving me alot of fun
have fun
truth
steve

amir meshy
November 2nd, 1999, 09:55 AM
You will have to write a simple code to convert from string to integer (or long, as you wish).

Just do a loop on the strings characters (you can use CString as an array).

CString str, str_out;
long ll=0;
str = "12345" // say that this string is the input

for (int i=0; i<str.GetLength(); i++)
{
ll = ll*10 + str[i] - '0';
}




for the printing you will use something like:

str_out.Format("hex:%x, decimal:%d", ll, ll);




This code does not contain recognition for "0x" and the hex letters 'a', 'b', etc. This you will add by your own.

Anyway, this is the way to do so.

Bye.

Amir Meshy, Software Engineer
eci Telecom