Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <bitset>
  4. #include <cstdint>
  5.  
  6. #include <SDL2/SDL.h>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.  
  13. uint32_t rgba = 0;
  14. uint8_t r { 0xFF };
  15. uint8_t g { 0xFF };
  16. uint8_t b { 0xf4 };
  17. uint8_t a { 0xFF };
  18.  
  19. rgba = (a << 24) + (b << 16) + (g << 8) + r;
  20.  
  21. cout << "Final color is " << setfill('0') <<
  22. setw(4) << hex << rgba << endl;
  23.  
  24. cout << resetiosflags(ios::showbase);
  25.  
  26. cout << "Binary color is " << bitset<32>(rgba) << endl;
  27.  
  28. uint8_t _r = 0;
  29. _r = rgba & 255;
  30. uint8_t _g = 0;
  31. _g = (rgba >> 8) & 255;
  32. uint8_t _b = 0;
  33. _b = (rgba >> 16) & 255;
  34.  
  35. cout << "r = " << unsigned(_r) << endl;
  36. cout << "g = " << unsigned(_g) << endl;
  37. cout << "b = " << unsigned(_b) << endl;
  38.  
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement