GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/Conversions/DecimalToHexaDecimal.java at master · estar12/Java Expand file tree/ Copy pathDecimalToHexaDecimal.javaMore file actions 30 lines (27 loc) · 1.07 KB / Copy pathDecimalToHexaDecimal.javaFile metadata and controls30 lines (27 loc) · 1.07 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 class DecimalToHexaDecimal { private static final int sizeOfIntInHalfBytes = 8; private static final int numberOfBitsInAHalfByte = 4; private static final int halfByte = 0x0F; private static final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; // Returns the hex value of the dec entered in the parameter. public static String decToHex(int dec) { StringBuilder hexBuilder = new StringBuilder(sizeOfIntInHalfBytes); hexBuilder.setLength(sizeOfIntInHalfBytes); for (int i = sizeOfIntInHalfBytes - 1; i >= 0; --i) { int j = dec & halfByte; hexBuilder.setCharAt(i, hexDigits[j]); dec >>= numberOfBitsInAHalfByte; } return hexBuilder.toString().toLowerCase(); } // Test above function. public static void main(String[] args) { System.out.println("Test..."); int dec = 305445566; String libraryDecToHex = Integer.toHexString(dec); String decToHex = decToHex(dec); System.out.println("Result from the library : " + libraryDecToHex); System.out.println("Result decToHex method : " + decToHex); } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |