Click here to Skip to main content
15,922,512 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: wifstream operator >> Pin
David Crow3-Nov-09 8:30
David Crow3-Nov-09 8:30 
GeneralRe: wifstream operator >> Pin
transoft3-Nov-09 8:46
transoft3-Nov-09 8:46 
QuestionRe: wifstream operator >> Pin
David Crow3-Nov-09 8:51
David Crow3-Nov-09 8:51 
AnswerRe: wifstream operator >> [modified] Pin
transoft3-Nov-09 9:01
transoft3-Nov-09 9:01 
QuestionRe: wifstream operator >> Pin
David Crow3-Nov-09 9:05
David Crow3-Nov-09 9:05 
QuestionHow to change IP address, DNS and Gateways Pin
RickyJiao3-Nov-09 3:39
RickyJiao3-Nov-09 3:39 
AnswerRe: How to change IP address, DNS and Gateways Pin
wangningyu3-Nov-09 3:47
wangningyu3-Nov-09 3:47 
GeneralRe: How to change IP address, DNS and Gateways Pin
RickyJiao3-Nov-09 3:50
RickyJiao3-Nov-09 3:50 
QuestionRe: How to change IP address, DNS and Gateways Pin
David Crow3-Nov-09 3:51
David Crow3-Nov-09 3:51 
AnswerRe: How to change IP address, DNS and Gateways Pin
RickyJiao3-Nov-09 3:58
RickyJiao3-Nov-09 3:58 
GeneralRe: How to change IP address, DNS and Gateways Pin
David Crow3-Nov-09 4:06
David Crow3-Nov-09 4:06 
GeneralRe: How to change IP address, DNS and Gateways Pin
RickyJiao3-Nov-09 4:15
RickyJiao3-Nov-09 4:15 
AnswerRe: How to change IP address, DNS and Gateways Pin
Randor 3-Nov-09 4:57
professional Randor 3-Nov-09 4:57 
Question[Message Deleted] Pin
davidcrow693-Nov-09 2:58
davidcrow693-Nov-09 2:58 
AnswerRe: Need help constructing B+ tree Pin
Stuart Dootson3-Nov-09 3:20
professionalStuart Dootson3-Nov-09 3:20 
QuestionRe: Need help constructing B+ tree Pin
David Crow3-Nov-09 3:22
David Crow3-Nov-09 3:22 
Answer[Message Deleted] Pin
davidcrow693-Nov-09 3:33
davidcrow693-Nov-09 3:33 
QuestionRe: Need help constructing B+ tree Pin
David Crow3-Nov-09 3:36
David Crow3-Nov-09 3:36 
AnswerRe: Need help constructing B+ tree Pin
Tim Craig3-Nov-09 14:21
Tim Craig3-Nov-09 14:21 
AnswerRe: Need help constructing B+ tree Pin
David Crow3-Nov-09 4:00
David Crow3-Nov-09 4:00 
QuestionConverting unsigned short int to its hex representation Pin
yeah10003-Nov-09 1:58
yeah10003-Nov-09 1:58 
Hello,
i ran into a bit of trouble when converting unsigned short int to its hex string representation. What i need is a two byte representation with a space between the bytes (e.g "0f 43" for 3907 of "00 ff" for 255)

The solution i came up with is the following:

unsigned char* CreateHexValues(unsigned short int inValue)
{
char Hex[5] = {0, 0, 0, 0, 0};
_itoa_s(inValue, Hex, 16);

unsigned char *hexOut = new unsigned char[5];
hexOut[2] = ' ';

if(inValue <= 15)
{
hexOut[0] = '0';
hexOut[1] = '0';
hexOut[3] = '0';
hexOut[4] = Hex[0];
}
else if(inValue > 15 && inValue <= 255)
{
hexOut[0] = '0';
hexOut[1] = '0';
hexOut[3] = Hex[0];
hexOut[4] = Hex[1];
}
else if(inValue > 255 && inValue <= 4095)
{
hexOut[0] = '0';
hexOut[1] = Hex[0];
hexOut[3] = Hex[1];
hexOut[4] = Hex[2];
}
else if (inValue > 4096)
{
hexOut[0] = Hex[0];
hexOut[1] = Hex[1];
hexOut[3] = Hex[2];
hexOut[4] = Hex[3];
}
return hexOut;
}
So my question is: is there a better/quicker way to do that? The problem is that when i convert it with _itoa_s it could be in the following formats: f43, 43, 3 (depending on inValue) without any zeros in front of it. Another problem is with the Hex[5] array, my inValue can never be bigger than 65535, but for some reason i get an assertion failure when i change its size to Hex[4] which should be enough for 65535. Why could that be?

Thanks for all replies in advance
AnswerRe: Converting unsigned short int to its hex representation Pin
Richard MacCutchan3-Nov-09 2:06
mveRichard MacCutchan3-Nov-09 2:06 
AnswerRe: Converting unsigned short int to its hex representation [fixed: thanks to David] Pin
CPallini3-Nov-09 2:30
mveCPallini3-Nov-09 2:30 
QuestionRe: Converting unsigned short int to its hex representation Pin
David Crow3-Nov-09 3:16
David Crow3-Nov-09 3:16 
AnswerRe: Converting unsigned short int to its hex representation Pin
CPallini3-Nov-09 3:29
mveCPallini3-Nov-09 3:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.