/* * @(#)TestUnsignedByte.java * * Summary: Test unsigned byte calculation. * * Copyright: (c) 2009 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.6+ * * Created with: IntelliJ IDEA IDE. * * Version History: * 1.0 2009-01-01 - initial version */ package com.mindprod.example; /** * Test unsigned byte calculation. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2009-01-01 - initial version * @since 2009-01-01 */ public final class TestUnsignedByte { // --------------------------- main() method --------------------------- /** * Test unsigned byte calculation * * @param args not used */ @SuppressWarnings( { "IncompatibleBitwiseMaskOperation" } ) public static void main( String[] args ) { // 0xca is a negative number considered as a signed byte. byte b = ( byte ) 0xca; // false, b sign extends, 0xca does not System.out.println( b == 0xca ); // true, b sign extends, 0xca sign extends System.out.println( b == ( byte ) 0xca ); // true, b chopped, 0xca does not sign extend System.out.println( ( b & 0xff ) == 0xca ); // false, b chopped, 0xca sign extends. System.out.println( ( b & 0xff ) == ( byte ) 0xca ); } }