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 01:21, local time: 2024/11/16 08:43,
TOP NEW HELP FIND: 
3.135.216.170: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://massmind.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 massmind.ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .