15,745,509 members
Home / Discussions / C / C++ / MFC

# C / C++ / MFC

 [Message Deleted] davidcrow693-Nov-09 2:58 davidcrow69 3-Nov-09 2:58
 Re: Need help constructing B+ tree Stuart Dootson3-Nov-09 3:20 Stuart Dootson 3-Nov-09 3:20
 Re: Need help constructing B+ tree David Crow3-Nov-09 3:22 David Crow 3-Nov-09 3:22
 [Message Deleted] davidcrow693-Nov-09 3:33 davidcrow69 3-Nov-09 3:33
 Re: Need help constructing B+ tree David Crow3-Nov-09 3:36 David Crow 3-Nov-09 3:36
 Re: Need help constructing B+ tree Tim Craig3-Nov-09 14:21 Tim Craig 3-Nov-09 14:21
 Re: Need help constructing B+ tree David Crow3-Nov-09 4:00 David Crow 3-Nov-09 4:00
 Converting unsigned short int to its hex representation yeah10003-Nov-09 1:58 yeah1000 3-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
 Re: Converting unsigned short int to its hex representation Richard MacCutchan3-Nov-09 2:06 Richard MacCutchan 3-Nov-09 2:06
 Re: Converting unsigned short int to its hex representation [fixed: thanks to David] CPallini3-Nov-09 2:30 CPallini 3-Nov-09 2:30
 Re: Converting unsigned short int to its hex representation David Crow3-Nov-09 3:16 David Crow 3-Nov-09 3:16
 Re: Converting unsigned short int to its hex representation CPallini3-Nov-09 3:29 CPallini 3-Nov-09 3:29
 Re: Converting unsigned short int to its hex representation yeah10003-Nov-09 4:41 yeah1000 3-Nov-09 4:41
 Re: Converting unsigned short int to its hex representation softwaremonkey4-Nov-09 11:23 softwaremonkey 4-Nov-09 11:23
 c++ code anilga3-Nov-09 1:51 anilga 3-Nov-09 1:51
 Re: c++ code Nikola Tanev3-Nov-09 2:08 Nikola Tanev 3-Nov-09 2:08
 Re: c++ code Richard MacCutchan3-Nov-09 2:15 Richard MacCutchan 3-Nov-09 2:15
 Re: c++ code CPallini3-Nov-09 2:18 CPallini 3-Nov-09 2:18
 Re: c++ code Michael Schubert3-Nov-09 2:36 Michael Schubert 3-Nov-09 2:36
 Re: c++ code David Crow3-Nov-09 3:13 David Crow 3-Nov-09 3:13
 Re: c++ code Rajesh R Subramanian3-Nov-09 3:15 Rajesh R Subramanian 3-Nov-09 3:15
 Re: c++ code Hamid_RT3-Nov-09 6:39 Hamid_RT 3-Nov-09 6:39
 OT CPallini3-Nov-09 6:50 CPallini 3-Nov-09 6:50
 Re: OT Hamid_RT3-Nov-09 19:28 Hamid_RT 3-Nov-09 19:28
 How can add path of all files to List Ctrl those are present in folder ? Le@rner3-Nov-09 1:51 Le@rner 3-Nov-09 1:51
 Last Visit: 31-Dec-99 18:00     Last Update: 28-Sep-23 14:46 Refresh ᐊ Prev1...2383238423852386238723882389239023912392 Next ᐅ