// // Hex class // part of the set of documents known as Java no sugar. // Copyright (c) 1996 Sunil Gupta, sunil@magnetic.demon.co.uk // placed into the public domain by the author // public class Hex extends Object { private static final String hexCodes = "0123456789abcdef"; private static final String hexPrefix = "0x"; public static String toHex(long value) { long remainder; byte digit; String answer = ""; remainder = value; while (remainder > 0) { digit = (byte) (remainder & 0xFl); answer = hexCodes.charAt(digit) + answer; remainder >>= 4; } return (hexPrefix + answer); } public static String toHex(int value) { return toHex((long) value); } public static String toHex(short value) { return toHex((long) value); } public static String toHex(byte value) { return toHex((long) value); } //############################################################################# // testing //############################################################################# public static void main( String argv[]) { String result; result = toHex(0x1234567812345678l); if ( result.equals("0x1234567812345678") ) System.out.println("Hex conversion worked just fine"); else System.out.println( "Hex conversion is b*******d" + "\n\tExpected: 0x1234567812345678" + "\n\t Got: " + result); } }
file: /Techref/language/JAVA/nosugar/comms/code/Hex.java, 1KB, , updated: 1996/10/16 01:21, local time: 2024/12/28 23:24,
3.137.186.186:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://sxlist.com/techref/language/JAVA/nosugar/comms/code/Hex.java"> language JAVA nosugar comms code Hex</A> |
Did you find what you needed? |
Welcome to sxlist.com!sales, advertizing, & kind contributors just like you! Please don't rip/copy (here's why Copies of the site on CD are available at minimal cost. |
Welcome to sxlist.com! |
.