Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public int getPackedRBG()
  2. {
  3.  
  4. return hexToDecimal(decimalToHex(channels[0]) + decimalToHex(channels[1]) + decimalToHex(channels[2]));
  5.  
  6. }
  7.  
  8. private String decimalToHex(int dec) {
  9. String digits = "0123456789ABCDEF";
  10. if (dec == 0) return "0";
  11. String hex = "";
  12. while (dec > 0) {
  13. int digit = dec % 16;
  14. hex = digits.charAt(digit) + hex;
  15. dec /= 16;
  16. }
  17. return hex;
  18. }
  19.  
  20. private int hexToDecimal(String hex)
  21. {
  22. String digits = "0123456789ABCDEF";
  23. hex = hex.toUpperCase();
  24. int dec = 0;
  25. for (int i = 0; i < hex.length(); i++) {
  26. char c = hex.charAt(i);
  27. int d = digits.indexOf(c);
  28. dec = 16*dec + d;
  29. }
  30. return dec;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement