Created
April 1, 2017 13:24
-
-
Save KentaYamada/31275765a48da3f43afe3bd954df826f to your computer and use it in GitHub Desktop.
Output ASCII with Hex(C / C++)
This file contains hidden or 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 <stdio.h> | |
int main(void) | |
{ | |
int i = 0; | |
const unsigned char text[] = "test\0"; | |
while(text[i] != '\0') { | |
printf("%02X\n", text[i]); | |
i++; | |
} | |
return 0; | |
} |
This file contains hidden or 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> | |
#include <iomanip> | |
int main() | |
{ | |
int i = 0; | |
const unsigned char text[] = "test\0"; | |
while(text[i] != '\0') { | |
std::cout << std::setw(2) << | |
std::setfill('0') << std::hex << | |
(short)text[i] << std::endl; | |
i++; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment