Click here to Skip to main content
15,882,113 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Heap Storage Corruption Pin
k505410-Jan-23 6:17
mvek505410-Jan-23 6:17 
AnswerRe: Heap Storage Corruption Pin
Graham Breach10-Jan-23 6:22
Graham Breach10-Jan-23 6:22 
GeneralRe: Heap Storage Corruption Pin
ForNow10-Jan-23 6:44
ForNow10-Jan-23 6:44 
GeneralRe: Heap Storage Corruption Pin
Graham Breach10-Jan-23 6:51
Graham Breach10-Jan-23 6:51 
AnswerRe: Heap Storage Corruption Pin
CPallini10-Jan-23 7:21
mveCPallini10-Jan-23 7:21 
GeneralRe: Heap Storage Corruption Pin
ForNow10-Jan-23 7:26
ForNow10-Jan-23 7:26 
GeneralRe: Heap Storage Corruption Pin
CPallini10-Jan-23 7:40
mveCPallini10-Jan-23 7:40 
AnswerRe: Heap Storage Corruption Pin
CPallini10-Jan-23 8:32
mveCPallini10-Jan-23 8:32 
If I got you, the code should return the hexadecimal representation of a bunch of bytes.
In order to avoid CRT-conflicts, you have to make the caller responsible of the output buffer allocation/deallocation. Something like this
C++
#include <iostream>
#include <cstddef>
using namespace std;

// in [INPUT]  - the binary array we wish to represent with an hex string
// size_in [INPUT] - the size (bytes) of the binary array
// out [OUTPUT] - the buffer receiving the hexadecimal representation of the binary data
// out_size [INPUT] - the size of the buffer. It should be at least (size_in*2+1) in order ot represent all the input data
size_t to_hex( unsigned char in[], size_t size_in, char out[], size_t size_out)
{
  size_t n;
  for (n=0; (n < size_in) && (n < (size_out-1)b/2); ++n)
  {
    unsigned char nibble;
    nibble = (in[n] >> 4); // the MSB nibble
    out[2*n] = nibble < 10 ? nibble + '0' : nibble - 10 + 'A';
    nibble = (in[n] & 15); // the LSB nibble
    out[2*n+1] = nibble < 10 ? nibble + '0' : nibble - 10 + 'A';
  }

  if ( 2*n < size_out)
    out[2*n] = '\0';

  return n;
}

// a little test
int main()
{
  unsigned char small[] = { 0x25, 0x37, 0x48, 0x42, 0x42 };

  char buffer[41];

  size_t size = to_hex( small, sizeof(small), buffer, sizeof(buffer));
  cout << "converted bytes " << size << ", hex string " << buffer << "\n";


  unsigned char large[256];
  for (size_t n=0; n<256; ++n)
  {
    large[n] = n;
  }

  size = to_hex( large, sizeof(large), buffer, sizeof(buffer));
  cout << "converted bytes " << size << ", hex string " << buffer << "\n";
}

"In testa che avete, Signor di Ceprano?"
-- Rigoletto

QuestionTo be deleted... Pin
arnold_w10-Jan-23 1:01
arnold_w10-Jan-23 1:01 
SuggestionRe: Why isn't my semi-editable ComboBox drawing the text in gray when the dropdown list isn't showing? Pin
Richard Deeming10-Jan-23 2:03
mveRichard Deeming10-Jan-23 2:03 
QuestionRe: Why isn't my semi-editable ComboBox drawing the text in gray when the dropdown list isn't showing? Pin
David Crow10-Jan-23 2:07
David Crow10-Jan-23 2:07 
QuestionTrying to Disable string operator= Pin
ForNow8-Jan-23 16:55
ForNow8-Jan-23 16:55 
AnswerRe: Trying to Disable string operator= Pin
k50548-Jan-23 17:49
mvek50548-Jan-23 17:49 
GeneralRe: Trying to Disable string operator= Pin
ForNow8-Jan-23 18:02
ForNow8-Jan-23 18:02 
AnswerRe: Trying to Disable string operator= Pin
Victor Nijegorodov8-Jan-23 22:50
Victor Nijegorodov8-Jan-23 22:50 
GeneralRe: Trying to Disable string operator= Pin
ForNow9-Jan-23 3:18
ForNow9-Jan-23 3:18 
GeneralRe: Trying to Disable string operator= Pin
Victor Nijegorodov9-Jan-23 3:56
Victor Nijegorodov9-Jan-23 3:56 
GeneralRe: Trying to Disable string operator= Pin
ForNow9-Jan-23 3:59
ForNow9-Jan-23 3:59 
AnswerRe: Trying to Disable string operator= Pin
CPallini8-Jan-23 23:20
mveCPallini8-Jan-23 23:20 
GeneralRe: Trying to Disable string operator= Pin
ForNow9-Jan-23 1:38
ForNow9-Jan-23 1:38 
QuestionWhere to find connect declaration of this mysql instace Pin
coco2437-Jan-23 13:29
coco2437-Jan-23 13:29 
AnswerRe: Where to find connect declaration of this mysql instace Pin
RedDk7-Jan-23 15:35
RedDk7-Jan-23 15:35 
AnswerRe: Where to find connect declaration of this mysql instace Pin
Richard MacCutchan7-Jan-23 21:06
mveRichard MacCutchan7-Jan-23 21:06 
GeneralRe: Where to find connect declaration of this mysql instace Pin
coco2438-Jan-23 1:27
coco2438-Jan-23 1:27 
GeneralRe: Where to find connect declaration of this mysql instace Pin
Richard MacCutchan8-Jan-23 1:37
mveRichard MacCutchan8-Jan-23 1:37 

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.