⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unsignedbyte.java

📁 这是架包java-unrar-0.2.jar的源码
💻 JAVA
字号:
/*
 * Copyright (c) 2007 innoSysTec (R) GmbH, Germany. All rights reserved.
 * Original author: Edmund Wagner
 * Creation date: 04.06.2007
 *
 * Source: $HeadURL$
 * Last changed: $LastChangedDate$
 * 
 * 
 * the unrar licence applies to all junrar source and binary distributions 
 * you are not allowed to use this source to re-create the RAR compression algorithm
 *
 * Here some html entities which can be used for escaping javadoc tags:
 * "&":  "&" or "&"
 * "<":  "&#060;" or "&lt;"
 * ">":  "&#062;" or "&gt;"
 * "@":  "&#064;" 
 */
package de.innosystec.unrar.unsigned;

import de.innosystec.unrar.crc.RarCRC;

/**
 * DOCUMENT ME
 *
 * @author $LastChangedBy$
 * @version $LastChangedRevision$
 */
public class UnsignedByte {
	
	public static byte longToByte(long unsignedByte1){
		return (byte) (unsignedByte1&0xff);
	}
	public static byte intToByte(int unsignedByte1){
		return (byte) (unsignedByte1&0xff);
	}
	public static byte shortToByte(short unsignedByte1){
		return (byte) (unsignedByte1&0xff);
	}
	
	
	public static short add(byte unsignedByte1, byte unsignedByte2){
		return (short) (unsignedByte1 + unsignedByte2);
	}
	
	public static short sub(byte unsignedByte1, byte unsignedByte2){
		
		return (short) (unsignedByte1 - unsignedByte2);
	}
	
	
	public static void main(String[] args)
	{
	//tests unsigned (signed)
		//add
		System.out.println(add((byte)0xfe,(byte)0x01)); //255 (-1)
		System.out.println(add((byte)0xff,(byte)0x01)); //0 (0)
		System.out.println(add((byte)0x7f,(byte)0x01)); //128 (-128)
		System.out.println(add((byte)0xff,(byte)0xff)); //254 (-2)
		
		//sub
		System.out.println(sub((byte)0xfe,(byte)0x01)); //253 (-3)
		System.out.println(sub((byte)0x00,(byte)0x01)); //255 (-1)
		System.out.println(sub((byte)0x80,(byte)0x01)); //127 (127)
		//mul
		System.out.println((byte)-1*(byte)-1);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -