Conversion between byte group and integer

Source: Internet
Author: User

C # integer occupies 4 bytes and should be stored in a 4-byte array. However, you can use the following method to store an integer smaller than 16777215 to a 3-byte array: </P> <p> int A = 999999; <br/> int B = 0; <br/> // converts an integer to a 3-byte array <br/> byte [] mytest = new byte [3]; <br/> mytest [0] = (byte) (A & 0xff); <br/> mytest [1] = (byte) (A> 8) & 0xff); <br/> mytest [2] = (byte) (A> 16) & 0xff ); <br/> // converts a 3-byte array to an integer. <br/> B = mytest [0] + (mytest [1] <8) + (mytest [2] <16); </P> <p>

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.