Java converts the number of symbols to the number of unsigned characters.

Source: Internet
Author: User

Java converts the number of symbols to the number of unsigned characters.
/**
* @ Author YangQuanqing yqq function: converts byte data in java into unsigned data within the range of 0--255.
*
*/
Public class ConvertToUnsigned {
Private static short [] tempByteU = null; // byte unsigned data


/**
* Returns the number of unsigned characters.
* @ Param a signed byte array
* @ Return byte unsigned data
*/
Public static short [] toGetUnsignedByte (byte [] ){
Int len = a. length;
TempByteU = new short [len];
For (int I = 0; I <len; I ++ ){
// If the data is less than 0, use the short type data and the calculation. The negative number is stored in the memory with a supplemental code.
If (a [I] <0 ){
TempByteU [I] = (short) (a [I] & 0x00ff );
} Else {// greater than 0, no need to change
TempByteU [I] = a [I];
}
}


Return tempByteU;
}


}

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.