Skip to content

Instantly share code, notes, and snippets.

@cordx56
Created January 1, 2019 10:42
Show Gist options
  • Save cordx56/52171490105911fb9756963772c47c0a to your computer and use it in GitHub Desktop.
Save cordx56/52171490105911fb9756963772c47c0a to your computer and use it in GitHub Desktop.
New year C++ script...
#include <iostream>
int hextoint(char hex) {
return ('0' <= hex && hex <= '9')? (int)(hex - '0') :
('A' <= hex && hex <= 'F')? 10 + (int)(hex - 'A') :
('a' <= hex && hex <= 'f')? 10 + (int)(hex - 'a') :
-1;
}
int main(void) {
char out[] = "4861707079204e6577205965617221";
std::cout << out << std::endl;
for (int i = 0; out[i] != '\0'; i++) {
std::cout << " 0x" << out[i] << out[++i];
}
std::cout << std::endl;
for (int i = 0; out[i] != '\0'; i++) {
std::cout << (char)(16 * hextoint(out[i]) + hextoint(out[++i]));
}
std::cout << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment