// Path: src/main/java/net/utp4j/data/bytes/exceptions/ByteOverflowException.java
// public class ByteOverflowException extends RuntimeException {
// 	
// 	private static final long serialVersionUID = -2545130698255742704L;
// 
// 	public ByteOverflowException(String message) {
// 		super(message);
// 	}
// 	
// 	public ByteOverflowException() {
// 		super("Overflow happened.");
// 	}
// }
// 
// Path: src/main/java/net/utp4j/data/bytes/exceptions/SignedNumberException.java
// public class SignedNumberException extends RuntimeException {
// 
// 	private static final long serialVersionUID = 1339267381376290545L;
// 	
// 	public SignedNumberException(String message) {
// 		super(message);
// 	}
// 	public SignedNumberException() {
// 		super("No negative values allowed");
// 	}
// 
// }


import net.utp4j.data.bytes.exceptions.ByteOverflowException;
import net.utp4j.data.bytes.exceptions.SignedNumberException;

package net.utp4j.data.bytes;



/**
 * 
 * Workaround to java's lack of unsigned types. 
 * Methods provided here intend to return integers, bytes and shorts which can be interpreted as unsigned types. 
 * E.G. Java's byte initialized with 0xFF will correspond to -1, with this workaround we can use more readable 
 * decimal value of 255 to convert it to -1, which in binary form is 11111111 and interpreted as an unsigned 
 * value, it would be 255. 
 * 
 * @author Ivan Iljkic (i.iljkic@gmail.com)
 *
 */

public final class UnsignedTypesUtil {

	public static final long MAX_UBYTE = 255;
	public static final long MAX_USHORT = 65535;
	public static final long MAX_UINT = 4294967295L;

		
	public static byte longToUbyte(long longvalue) {
		if (longvalue > MAX_UBYTE) {
			throw new ByteOverflowException(getExceptionText(MAX_UBYTE, longvalue));
		} else if (longvalue < 0) {

// Path: src/main/java/net/utp4j/data/bytes/exceptions/ByteOverflowException.java
// public class ByteOverflowException extends RuntimeException {
// 	
// 	private static final long serialVersionUID = -2545130698255742704L;
// 
// 	public ByteOverflowException(String message) {
// 		super(message);
// 	}
// 	
// 	public ByteOverflowException() {
// 		super("Overflow happened.");
// 	}
// }
// 
// Path: src/main/java/net/utp4j/data/bytes/exceptions/SignedNumberException.java
// public class SignedNumberException extends RuntimeException {
// 
// 	private static final long serialVersionUID = 1339267381376290545L;
// 	
// 	public SignedNumberException(String message) {
// 		super(message);
// 	}
// 	public SignedNumberException() {
// 		super("No negative values allowed");
// 	}
// 
// }


// Path: src/main/java/net/utp4j/data/bytes/UnsignedTypesUtil.java
import net.utp4j.data.bytes.exceptions.ByteOverflowException;
import net.utp4j.data.bytes.exceptions.SignedNumberException;

package net.utp4j.data.bytes;



/**
 * 
 * Workaround to java's lack of unsigned types. 
 * Methods provided here intend to return integers, bytes and shorts which can be interpreted as unsigned types. 
 * E.G. Java's byte initialized with 0xFF will correspond to -1, with this workaround we can use more readable 
 * decimal value of 255 to convert it to -1, which in binary form is 11111111 and interpreted as an unsigned 
 * value, it would be 255. 
 * 
 * @author Ivan Iljkic (i.iljkic@gmail.com)
 *
 */

public final class UnsignedTypesUtil {

	public static final long MAX_UBYTE = 255;
	public static final long MAX_USHORT = 65535;
	public static final long MAX_UINT = 4294967295L;

		
	public static byte longToUbyte(long longvalue) {
		if (longvalue > MAX_UBYTE) {
			throw new ByteOverflowException(getExceptionText(MAX_UBYTE, longvalue));
		} else if (longvalue < 0) {

			throw new SignedNumberException(getExceptionText(MAX_UBYTE, longvalue));
