Last active
July 10, 2018 19:06
-
-
Save MocoNinja/120cc331aba57e38cddc750d3c78e12c to your computer and use it in GitHub Desktop.
pr0b1tscpp
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> // Manipulate IO | |
using namespace std; | |
void print_hex(unsigned int* number) | |
{ | |
cout << "0x" << setfill('0') << setw(8) << hex << *number << endl; | |
} | |
int main() | |
{ | |
// 0xFF123456 | |
unsigned char alpha = 0xFF; | |
unsigned char red = 0x12; | |
unsigned char green = 0x34; | |
unsigned char blue = 0x56; | |
unsigned int color = 0; | |
// SLOW | |
print_hex(&color); | |
color += alpha; | |
print_hex(&color); | |
color <<= 8; | |
print_hex(&color); | |
color += red; | |
print_hex(&color); | |
color <<= 8; | |
print_hex(&color); | |
color += green; | |
print_hex(&color); | |
color <<= 8; | |
print_hex(&color); | |
color += blue; | |
print_hex(&color); | |
// C00L | |
color = 0; | |
print_hex(&color); | |
color = alpha << 24 | red << 16 | green << 8 | blue; | |
print_hex(&color); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment