MCPcopy Create free account
hub / github.com/RangeNetworks/openbts / hex_string_to_binary

Function hex_string_to_binary

TransceiverRAD1/RAD1Cmd.cpp:103–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103static unsigned char *
104hex_string_to_binary (const char *string, int *lenptr)
105{
106 int sl = strlen (string);
107 if (sl & 0x01){
108 fprintf (stderr, "%s: odd number of chars in <hex-string>\n", prog_name);
109 return 0;
110 }
111
112 int len = sl / 2;
113 *lenptr = len;
114 unsigned char *buf = new unsigned char [len];
115
116 for (int i = 0; i < len; i++){
117 int hi = hexval (string[2 * i]);
118 int lo = hexval (string[2 * i + 1]);
119 if (hi < 0 || lo < 0){
120 fprintf (stderr, "%s: invalid char in <hex-string>\n", prog_name);
121 delete [] buf;
122 return 0;
123 }
124 buf[i] = (hi << 4) | lo;
125 }
126 return buf;
127}
128
129static void
130print_hex (FILE *fp, unsigned char *buf, int len)

Callers 1

mainFunction · 0.70

Calls 1

hexvalFunction · 0.70

Tested by

no test coverage detected