Created
January 1, 2019 10:42
-
-
Save cordx56/52171490105911fb9756963772c47c0a to your computer and use it in GitHub Desktop.
New year C++ script...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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