please dont rip this site

Language Java Nosugar Comms Code Hex.java

// 
//	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 02:21, local time: 2024/8/15 15:05,
TOP NEW HELP FIND: 
18.219.91.251: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?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://ecomorder.com/Techref/language/java/nosugar/comms/code/Hex.java"> language java nosugar comms code Hex</A>

Did you find what you needed?

 

Welcome to ecomorder.com!

 

Welcome to ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .