Neodatis. ODB Article 2 everything is bit

Source: Internet
Author: User

Org. neodatis. ODB. Core. Io. bytearrayconverter

The function of this class is: converts array of bytes into Native objects and native objects into array of bytes

Public class bytearrayconverter {
......

/**
* Bit binary bits (or bits) byte 1 byte = 8bit kilobyte (Kb) kilobytes of megabyte (MB) megabytes
* 1 MB = 1024kb = 1024*1024 byte gigabyte (GB) terabyte (TB) Too byte petabyte (PB)
* Exabyte (EB) zetabyte (zb) yottabyte (Yb) nonabyte (NB) doggabyte (db)
*
* Byte type 1 byte-128-127 short integer 2 bytes-2 15 power-2 15 power-1 int integer 4 bytes
* 31 Power-2 31 Power-1 long integer 8 bytes-63 power of 2 ~ 63 power-1 of 2
*
* @ Param s
* @ Return: First low, then high
*/
Public static byte [] Using tobytearray (short S ){
Byte B [] = new byte [2];
Int I, shift;
For (I = 0, shift = 8; I <2; I ++, shift-= 8 ){
B [I] = (byte) (0xff & (S> shift); // & 0000 0000 1111 first low, then high
}
Return B;
}

Public static short bytearraytoshort (byte [] bytes ){
Short result = 0;

For (INT I = 0; I <2; I ++ ){
Result <= 8; // left shift out the last byte
Result | = bytes [I] & 0xff; // or in the new byte
}
Bytes = NULL;
Return result;
}

......

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.