|
Hi All,
Please let me know some hints to convert a hex value to a string..
Regards,
Spk521
|
|
|
|
|
Click here->[^]
I believe in LOVE AT FIRST SITE...
Bcoz I have loved my Mother...
even since I opened my eyes...(ICAN)
|
|
|
|
|
It depends what you mean by convert. Do you want the hex value to appear as hex in the string (e.g. 0x3739 --> "0x3739") or do you want to display it as characters (e.g. 0x3739 --> "79")?
I must get a clever new signature for 2011.
|
|
|
|
|
ys.. i need to convert hex to its corresponding ascii value...
|
|
|
|
|
Hi,
Please try this..
char str[] = "01-15-43-43-34-37-37-41";
char delims[]="-";
CString strAscii = _T("");
CString strModelN0 = _T("");
char *result= NULL;
result = strtok(str,delims);
while(result != NULL)
{
result = strtok(NULL, delims);
if(NULL != result)
{
strAscii.Format(_T("%c"),hexToAscii(result));
strModelN0 += strAscii;
}
}
char hexToAscii(char *Num)
{
char hex[10]= "0x";
strcat(hex,Num);
return strtol(hex, NULL, 16);
}
Regards,
Spidy
|
|
|
|
|
Thanks laj its working....
|
|
|
|
|
You missed the first number.
I must get a clever new signature for 2011.
|
|
|
|
|
in addition to his above example, if your hex is in some int type variable, you may try this also,
int k = 0x3739;
CString out;
while(k > 0) {
out += (char)k % 0x100;
k /= 0x100;
}
strrev(out.GetBuffer(0));
cout <<(LPCTSTR)out <<endl;
|
|
|
|
|
S p k 521 wrote: ...convert hex to its corresponding ascii value...
This makes no sense? Are you wanting to convert from base-16 to base-10?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
You can do this easily using std::ostringstream[^].
Here is a small example for you:
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
int main()
{
const unsigned int num1 = 0x1234, num2 = 1234;
std::ostringstream oss;
oss << "0x" << std::hex << num1;
std::string strFirstNumHex = oss.str();
oss.str(std::string());
oss << "0x" << std::hex << num2;
std::string strSecondNumHex = oss.str();
oss.str(std::string());
oss << std::dec << num1;
std::string strFirstNumDec = oss.str();
oss.str(std::string());
oss << std::dec << num2;
std::string strSecondNumDec = oss.str();
std::cout << "Numbers in HEX: " << strFirstNumHex << ", " << strSecondNumHex << "\t"
<< "Numbers in DEC: " << strFirstNumDec << ", " << strSecondNumDec;
std::cin.get();
return 0;
}
As you can see from the above example strFirstNumHex and strSecondNumHex contain hex string representations of the test integers (strFirstNumHex = 0x1234 and strSecondNumHex = 0x4d2 ). strFirstNumDec and strSecondNumDec contain decimal string representations of the test integers.
If you don't need the "0x" prefix for your Hex strings you can remove this prefix from specified lines in above example. I hope this helps.
NOTE: For clearing the content of the stream buffer I usually use: oss.str(""); , but it messes the formatting of the code block and I changed it to oss.str(std::string()); .
|
|
|
|
|
thank you very much experts...
|
|
|
|
|
Hi
Any sample code for ActiveX Component use 2D graph in MFC
Regards
M.Mathivanan
|
|
|
|
|
|
I am self-taught in C++ and this is as deep as I've ever been in messaging.
I have a modeless parent dialog maintaining a typed ptr list of modeless child dialog pointers. The children are all of the same class and hold memory and file resources (sets of parts and subassembly populations). The parent modeless supervises set operations on the children: unary transforms such as rotations, and binary operations such as set intersection, etc. So the parent is usually holding a kind of focus on one or two of the child operands.
I have been several days now, learning different ways that the parent dialog can crash via a null position pointer in the collection class operations, or crash via a pointer to a deleted child. I'm not crying about it, I needed the knowlege, anyway.
At this point my code no longer crashes but I have to perform two mouse clicks to close an inactive child; first click activates and second click closes ("close" means user clicked the X-button in the menu bar). The activation click causes the parent to lose its hold on current operands. Here are my event captures:
int CPop::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
if(nHitTest != HTSYSMENU)
{
GetParent()->PostMessageW(WMU_POP_TO_POPMAN_CHILD_M_ACTIVE, (WPARAM)0, m_ptoken);
}
return MA_ACTIVATEANDEAT;
}
void CPop::OnSysCommand(UINT nID, LPARAM lParam)
{
if((0xfff0 & nID) == SC_CLOSE)
{
OnClose();
}
else
{
GetParent()->PostMessageW(WMU_POP_TO_POPMAN_CHILD_M_ACTIVE, (WPARAM)0, m_ptoken);
}
}
I saw a #define HTCLOSE in winuser but it is not listed in the docs for OnMouseActivate(). Of course I tried it but it is unreliable.
Child acivation causes the parent to lose "currency" of previously activated children, a real pia.
I would like to know a method for one-click closing an inactive child. Just point me to an article if there is one.
Tadeusz Westawic
Sum quid sum.
|
|
|
|
|
Hi all,
I am trying to open the (jpeg)image and store it into an array(matrix) format.
I am not getting how to start,can anyone please help me in doing this.
Thanks
Raj
|
|
|
|
|
hi,
Do you have any code already? If so, it would be useful to post the details of your decoder.
If you haven't decided on a decoder yet, using the CImage[^] class could be a good one to consider.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
another option, if you can use Gdi+, is to go for Bitmap & BitmapData classes.
|
|
|
|
|
It depends what you want to achieve. Also depends how your jpeg is represented to you, i.e. do you have a file handle, etc etc.
So you if you post some more details, it'll be easy for us to help.
--
Arman
|
|
|
|
|
Basically JPEG is compressed file format.
Hope this[^] will help you a bit.
Regards,
Paresh.
|
|
|
|
|
|
I want an MFC SDI application frame window with a custom title bar, and I am using this code:
http://www.microsoft.com/msj/0197/c/c0197.aspx
It sort of works. Unfortunately the custom title bar causes the buttons in the top right (minimize, maximize and close) to shrink in width, and hence the end result is a mess.
Has anyone come across this problem, or know of an alternative? Thanks.
modified on Thursday, January 6, 2011 5:19 AM
|
|
|
|
|
Is it just me or is there something wrong with that link you provided? It doesn't seem to point at where it suposedly does.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
>Nothing is free in the universe.<
modified on Thursday, January 6, 2011 5:44 AM
|
|
|
|
|
Not it's not just you. Thanks for pointing it out. I've fixed the link.
|
|
|
|
|
I have a menu File->Exit
I need to change the menu text at run time SO I used
CMenu::ModifyMenu() funtion to do that.
I am able to set the text for "Exit" but not for "File"
Becuse for "Exit" I know the ID, but "File" no ID is specified.
How can I chnage text of "File"?
|
|
|
|
|
You can modify menu items by ID or position; see here[^] for information on modify by position.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|