MCPcopy Create free account
hub / github.com/ashkulz/NppFTP / HexToData

Method HexToData

src/StringUtils.cpp:341–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

339}
340
341char* SU::HexToData(const char * hex, int len, bool addZero) {
342 if (len == -1)
343 len = strlen(hex);
344
345 if (len%2 != 0)
346 return NULL;
347
348 len = len/2;
349 unsigned char * data = new unsigned char[len + (addZero?1:0)];
350
351 for(int i = 0; i < len; i++) {
352 data[i] = 0;
353
354 if (hex[i*2] <= '9')
355 data[i] += (hex[i*2] - '0') * 16;
356 else
357 data[i] += ((hex[i*2] - 'A') + 10) * 16;
358
359 if (hex[i*2+1] <= '9')
360 data[i] += (hex[i*2+1] - '0');
361 else
362 data[i] += (hex[i*2+1] - 'A') + 10;
363 }
364
365 if (addZero) {
366 data[len] = 0;
367 }
368
369 return (char*)data;
370}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected