Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.util.ArrayList;
- import java.util.Arrays;
- public class ASCIItoRGB{
- public static void main(String args[]) {
- String hexExtra = null;
- // Input
- String asciiValue = "This is a test";
- // ASCII to Hex
- char[] c = asciiValue.toCharArray();
- StringBuffer hexValue = new StringBuffer();
- for(int i=0; i<c.length; i++) {
- hexValue.append(Integer.toHexString((int)c[i]));
- }
- String hexString = hexValue.toString();
- // Hex to RGB
- ArrayList<Color> rgbValues = new ArrayList<Color>();
- while(hexString.length() >= 6) {
- String tempval = "#" + hexString.substring(0,5);
- rgbValues.add(Color.decode(tempval));
- hexString = hexString.substring(tempval.length(), hexString.length());
- if(hexString.length() < 6) {
- hexExtra = hexString;
- }
- }
- // Output
- System.out.println("ASCII VALUE: " + asciiValue);
- System.out.println("CHAR ARRAY: " + Arrays.toString(c));
- System.out.println("EXTRA DATA: " + hexExtra);
- System.out.println("HEX VALUE: " + hexValue.toString());
- System.out.println("RGB VALUES: " + rgbValues.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement