|
hey does anyone know how to quickly convert a hex value to its corresponding character representation. For example, 4E would convert to F or 50 would convert to P, etc.. etc.. etc.. thanks in advance
|
|
|
|
|
For the below function FkHex2ByteA the resulting byte can be treated (cast) as a char if you know the hex value will map to an ascii character value.
typedef unsigned char byte;
cchar *VkCharHexL = "0123456789abcdef";
byte FkHex2ByteA( char C1, char C2 )
{
C1 = tolower(C1);
C2 = tolower(C2);
cchar *sp1 = strchr(VkCharHexL, C1),
*sp2 = strchr(VkCharHexL, C2);
if( !sp1 || !sp2 ) return(0);
return( ((sp1-VkCharHexL)<<4) + (sp2-VkCharHexL) );
}
void FkByte2HexA( byte B, char &C1, char &C2 )
{
C1 = VkCharHexL[B >> 4];
C2 = VkCharHexL[B & 0x0F];
}
...cmk
Save the whales - collect the whole set
|
|
|
|
|
so it comes together, I suppose I need to dejoin them first. Why add 4 to it and then together? Its insane that this function even works. I don't like that I have to split the value, is that mandatory? I do like that it works to go from hex to dec, which does make dec to ascii easy to do. I could probably do: sprintf(chr,"%s",dec);, right.. close?
thanks
|
|
|
|
|
borono wrote: Why add 4 to it and then together
You don't add 4, you shift left 4 bits.
borono wrote: I don't like that I have to split the value
I gave the code i did to give you a low-level understanding of what is happening.
As others have pointed out in other threads you can also use strtol or sscanf.
I am assuming the hex is in a string e.g. "F012".
As such just loop through the hex string 2 char at a time.
e.g. something like
void HexToStr( cchar *HEX, char *STR )
{
for( ulong i = 0, j = 0; HEX[i] && HEX[i+1]; i+=2, j++ ) {
STR[j] = (char)FkHex2ByteA(HEX[i], HEX[i+1]);
}
}
... of course you would
- add HEX/STR buffer lengths as function param
- do proper error checking
- do more validation that HEX actually contains hex string
- ...
...cmk
Save the whales - collect the whole set
|
|
|
|
|
luckily no. I have the flow dripping --one at a time. 4E then FF, and on; till the end of time or size of transmission (which ever comes first). I thought, initially, I was to split, lets say 4E, making that value 4 and E, and it appears that is indeed the case. I think the function you gave should be good, so I will try it. i will let you know if it works, thanks for the examples.
-- modified at 23:44 Friday 28th April, 2006
Found here: http://users.powernet.co.uk/eton/kandr2/krx203.html
Slightly Modified Code:
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int hexalpha_to_int(int c)
{
char hexalpha[] = "aAbBcCdDeEfF";
int i;
int answer = 0;
for(i = 0; answer == 0 && hexalpha[i] != '\0'; i++)
{
if(hexalpha[i] == c)
{
answer = 10 + (i / 2);
}
}
return answer;
}
unsigned int htoi(const char s[])
{
unsigned int answer = 0;
int i = 0;
int valid = 1;
int hexit;
if(s[i] == '0')
{
++i;
if(s[i] == 'x' || s[i] == 'X')
{
++i;
}
}
while(valid && s[i] != '\0')
{
answer = answer * 16;
if(s[i] >= '0' && s[i] <= '9')
{
answer = answer + (s[i] - '0');
}
else
{
hexit = hexalpha_to_int(s[i]);
if(hexit == 0)
{
valid = 0;
}
else
{
answer = answer + hexit;
}
}
++i;
}
if(!valid)
{
answer = 0;
}
return answer;
}
int conv(char *hex)
{
char *endp = NULL;
unsigned int result;
unsigned int check;
result = htoi(hex);
check = (unsigned int)strtoul(hex, &endp, 16);
if((*endp != '\0' && result == 0) || result == check)
{
printf("%u\n", result);
}
else
{
MessageBox(NULL,"Invalid hexadecimal value.",0,0);
}
return 0;
}
int main(void)
{
conv("4E");
return 0;
}
solved, thank you
|
|
|
|
|
|
hey guys, thanks for the input. I just changed %u to %c.
|
|
|
|
|
So you're wanting to take a string with a hex number in it, and return the character with that ASCII code?
char ch = (char)strtol("4e", NULL, 16);
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I, m writing something about CButton and CCaptionButton (buttons for the titlebar)and I need some text or same exemples. If you have anything please help me.
Vasko Drenoski
|
|
|
|
|
->First set your goal what to do,
->Try to work on it,
->If you have any problem in it...Then come with same
Knock out "T" from CAN'T
You 'CAN' if you think you 'CAN'
|
|
|
|
|
Can you be more specific.
|
|
|
|
|
Hi guys,
There is a small bug in this great class (v3.9) and I'm puzzled on how to fix it.
Its regarding tooltips:
Once a tooltip is enabled on a button it works fine. You hover over the button and, as expected, the tooltip is displayed. But, once the button has been pressed the tooltip dissapears never to be seen again!
Any help would be...well, helpfull
|
|
|
|
|
This seems to be a general Windows-ism - I have seen the same bug in with WTL applications, and even an MS guy who works on the WTL framework cannot track it down.
|
|
|
|
|
Hi together,
I'm still working with VC6 and would like to install the latest Platform SDK for it. At Microsoft I can only find the "Windows Server 2003 SP1 Platform SDK 2" version. However, I somewhere read on the web that the "Platform SDK - February 2003" version is the latest one that works with VC6. But I can't find it on the web. Does anybody know where I can get it or how I can update my PSDK for VC6?
Thank you very much,
Marcus.
|
|
|
|
|
khb wrote: Does anybody know where I can get it or how I can update my PSDK for VC6?
are you having the MSDN suscription?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I have to admit that I'm not a professional programmer. Ok, I have a legal version of VC6 that I bought several years ago. I simply used it for a long time. Then, somewhen in 2001 or 2002 I downloaded a PSDK version from the MS website as I needed it to use some new functions. Now I want to update my PSDK to make again use of some new functions that the "Feb 2003" release definitively contains. Any idea how I can accomplish that?
Thank you very much for your help,
Marcus.
|
|
|
|
|
I have a code that runs in Visual (Studio 6) well, anybody can tell me what should I do to run the same code in Visul 2005? I get 200 errors for the new version on the visual studio.
Thanks for any ideas
|
|
|
|
|
Post the errors and someone will be able to help you out.
Regards,
Nish
|
|
|
|
|
Errors like:
c:\wehost\api\weapiclass.cpp(263) : error C2184: 'void' : illegal type for __except expression
c:\wehost\tools\cfgclass.cpp(234) : warning C4258: 'size' : definition from the for loop is ignored; the definition from the enclosing scope is used
c:\wehost\tools\cfgclass.cpp(186) : definition of 'size' ignored
c:\wehost\tools\logger.cpp(353) : warning C4996: '_ftime64' was declared deprecated
and so on.
Please note that It was working fine in Visual 6.
Best regards,
|
|
|
|
|
|
Errors like:
c:\wehost\api\weapiclass.cpp(263) : error C2184: 'void' : illegal type for __except expression
c:\wehost\tools\cfgclass.cpp(234) : warning C4258: 'size' : definition from the for loop is ignored; the definition from the enclosing scope is used
c:\wehost\tools\cfgclass.cpp(186) : definition of 'size' ignored
c:\wehost\tools\logger.cpp(353) : warning C4996: '_ftime64' was declared deprecated
and so on.
Please note that It was working fine in Visual 6.
Best regards,
|
|
|
|
|
please be more specific in your post? 'void'?
|
|
|
|
|
Hi all,
I have an array that have 78840 items in it.
and every item has maximum 10 digits in it(like pt[78840]=1234567890)
I want to send this array to another computer.
What is a fast (fastest) way to send them (in about miliseconds)??
Please help me...
thanks.
Every new thing you learn,Gives you a new personality.
|
|
|
|
|
two solutions essentially. same network?
Kuphryn
|
|
|
|
|
dSolariuM wrote: I want to send tArhis array to another computer.What is a fast (fastest) way to send them (in about miliseconds)??
For transffering data from one computer to another you must be using Socket (Connection oriented),IMHO that only fastest way available in market today
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|