Skip to content

Instantly share code, notes, and snippets.

@ishikawash
Created August 26, 2020 03:56
Show Gist options
  • Save ishikawash/1932e33d20221cb03b37af1267b67955 to your computer and use it in GitHub Desktop.
Save ishikawash/1932e33d20221cb03b37af1267b67955 to your computer and use it in GitHub Desktop.
The NUXI Problem
#include <iostream>
int main()
{
char text[] = { 'U', 'N', 'I', 'X' };
uint16_t* p = reinterpret_cast<uint16_t*>(text);
for (int i = 0; i < sizeof(text)/sizeof(uint16_t); i++)
{
uint16_t a = *p;
for (int i = sizeof(uint16_t) - 1; i >= 0; i--)
{
// Print character from high byte to low byte.
char ch = ((a >> i * 8) & 0xFF);
std::cout << ch;
}
p++;
}
std::cout << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment