Skip to content

Instantly share code, notes, and snippets.

@KentaYamada
Created April 1, 2017 13:24
Show Gist options
  • Save KentaYamada/31275765a48da3f43afe3bd954df826f to your computer and use it in GitHub Desktop.
Save KentaYamada/31275765a48da3f43afe3bd954df826f to your computer and use it in GitHub Desktop.
Output ASCII with Hex(C / C++)
#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;
}
#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