[c++] Encode/Decode URLs in C++

the juicy bits

#include <ctype.h> // isdigit, tolower

from_hex(char ch) {
  return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
}

char to_hex(char code) {
  static char hex[] = "0123456789abcdef";
  return hex[code & 15];
}

noting that

char d = from_hex(hex[0]) << 4 | from_hex(hex[1]);

as in

// %7B = '{'

char d = from_hex('7') << 4 | from_hex('B');