1 26 27 package net.sourceforge.groboutils.codecoverage.v2.util; 28 29 import java.util.Comparator ; 30 import java.util.zip.CRC32 ; 31 import java.util.zip.Checksum ; 32 33 34 43 public class HexUtil 44 { 45 protected static HexUtil s_instance = new HexUtil(); 46 47 48 public static class TwoShorts { 49 public short a; 50 public short b; 51 52 public TwoShorts() {} 53 public TwoShorts( short a, short b ) 54 { 55 this.a = a; 56 this.b = b; 57 } 58 } 59 60 61 64 protected HexUtil() 65 { 66 } 68 69 70 public static final HexUtil getInstance() 71 { 72 return s_instance; 73 } 74 75 76 83 public boolean parseTwoHex( String text, final TwoShorts ts, 84 final char sep, final int startPos ) 85 { 86 if (text == null || ts == null || startPos < 0) 87 { 88 return false; 89 } 90 91 int sepPos = text.indexOf( sep, startPos ); 92 if (sepPos <= 0 || sepPos >= text.length()) 93 { 94 return false; 95 } 96 97 try 98 { 99 ts.a = (short)Integer.parseInt( 100 text.substring( startPos, sepPos ), 16 ); 101 ts.b = (short)Integer.parseInt( 102 text.substring( sepPos + 1 ).trim(), 16 ); 103 } 104 catch (NumberFormatException e) 105 { 106 return false; 107 } 108 109 return true; 110 } 111 112 113 142 } 143 | Popular Tags |