From 745553530ce8e967f331f9754aa3f2d9511e615b Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 4 Sep 2014 07:55:48 +0200 Subject: add behex and unhex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libgamma/CRTCInformation.java | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/libgamma/CRTCInformation.java b/src/libgamma/CRTCInformation.java index 384ad5c..307ec8b 100644 --- a/src/libgamma/CRTCInformation.java +++ b/src/libgamma/CRTCInformation.java @@ -452,5 +452,41 @@ public class CRTCInformation */ public final LibgammaException gamma_error; + + + /** + * Convert a raw representation of an EDID to a lowercase hexadecimal representation. + * + * @param edid The EDID in raw representation. + * @return The EDID in lowercase hexadecimal representation, + */ + public static String behex(byte[] edid) + { + char[] rc = new char[edid.length * 2]; + for (int i = 0; i < edid.length; i++) + { rc[i * 2 + 0] = "0123456789abcdef".charAt((edid[i] >> 4) & 15); + rc[i * 2 + 1] = "0123456789abcdef".charAt((edid[i] >> 0) & 15); + } + return new String(rc); + } + + /** + * Convert an hexadecimal representation of an EDID to a raw representation. + * + * @param edid The EDID in hexadecimal representation. + * @return The EDID in raw representation, it will be half the length + * of edid (the input value). + */ + public static byte[] unhex(String edid) + { + byte[] rc = new byte[edid.length() / 2]; + edid = edid.toLowerCase(); + for (int i = 0; i < rc.length; i++) + { rc[i] = (byte)("0123456789abcdef".indexOf(edid.charAt(i * 2 + 0)) << 4); + rc[i] |= (byte)("0123456789abcdef".indexOf(edid.charAt(i * 2 + 1)) << 0); + } + return rc; + } + } -- cgit v1.2.3-70-g09d2