return a hexadecimal printed representation of the specified BigInteger object. the value is formatted to fit on lines of at least 75 characters, with embedded newlines. Words are separated for readability, with eight words (32 bytes) per line.
(BigInteger b)
| 144 | * separated for readability, with eight words (32 bytes) per line. |
| 145 | */ |
| 146 | public static String toHexString(BigInteger b) { |
| 147 | String hexValue = b.toString(16); |
| 148 | StringBuffer buf = new StringBuffer(hexValue.length()*2); |
| 149 | |
| 150 | if (hexValue.startsWith("-")) { |
| 151 | buf.append(" -"); |
| 152 | hexValue = hexValue.substring(1); |
| 153 | } else { |
| 154 | buf.append(" "); // four spaces |
| 155 | } |
| 156 | if ((hexValue.length()%2) != 0) { |
| 157 | // add back the leading 0 |
| 158 | hexValue = "0" + hexValue; |
| 159 | } |
| 160 | int i=0; |
| 161 | while (i < hexValue.length()) { |
| 162 | // one byte at a time |
| 163 | buf.append(hexValue.substring(i, i+2)); |
| 164 | i+=2; |
| 165 | if (i!= hexValue.length()) { |
| 166 | if ((i%64) == 0) { |
| 167 | buf.append("\n "); // line after eight words |
| 168 | } else if (i%8 == 0) { |
| 169 | buf.append(" "); // space between words |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | return buf.toString(); |
| 174 | } |
| 175 | } |