Java Big Endian&little Endian__java

Source: Internet
Author: User

About big endian and Little endian

Java in the short, int data big endian turn little endian test code, as follows:

Package com.zyg.test;

public class Endiantest {public
	static void Main (string[] args) {short
		x=257;//00000001 00000001 (8 times + 1 for 2)
		Short x2 = Bigendian2littleendian16 (x);
		System.out.println ("x=" +x+ ", x2=" +x2);
		
		int y=257;  00000000 00000000 00000001 00000001 (2 y2 + 8)
		int = Bigendian2littleendian32 (y);
		System.out.println ("y=" +y+ ", y2=" +y2);
	}
	
	/**
	 * Convert Big-endian to Little-endian 
	 * * *
	/private static final short Bigendian2littleendian16 x) {return
		(short) ((X & 0xFF) << 8 | 0xFF & (x >> 8));
	}

	/**
	 * Convert Big-edian to Little-edian 
	 * * *
	/private static final int bigendian2littleendian32 (int x) {
 return (x & 0xFF) << 24 | (0xFF & x >> 8) << 16 | (0xFF & x >>) << 8
				| (0xFF & x >>);
	}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.