Skip to content

Instantly share code, notes, and snippets.

@yim1990
Created August 25, 2014 05:57
Show Gist options
  • Save yim1990/064adb78ee168091da4d to your computer and use it in GitHub Desktop.
Save yim1990/064adb78ee168091da4d to your computer and use it in GitHub Desktop.
Hex color extraction from string
public class StringHexUtil {
public static String stringToRgbHash(String source) {
int hash=source.hashCode();
int r = (hash & 0xFF0000) >> 16;
int g = (hash & 0x00FF00) >> 8;
int b = hash & 0x0000FF;
return "#"+Integer.toHexString(r)+Integer.toHexString(g)+Integer.toHexString(b);
}
}
@yim1990
Copy link
Author

yim1990 commented Aug 25, 2014

It`s useful when you want to transform string into hex web color.
Same string represents same color.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment