C # small end to big Endian Little Endian

Source: Internet
Author: User

second, what is big and small end

The definitions of Big-endian and Little-endian are as follows:
1) Little-endian is the low byte emissions in the memory of the lower address, high-byte emissions at the high address of the memory.
2) Big-endian is the high-bit bytes emitted at the low address of the memory, low bytes emitted in the memory of the higher address.
For example, for example, digital 0x12 34 56 78 is represented in memory:

1) Big-endian mode:

Low address-----------------> High address
0x12 |  0x34 |  0x56 | 0x78

2) Small terminal mode:

Low address------------------> High address
0x78 |  0x56 |  0x34 | 0x12

It can be seen that the big-endian pattern is similar to string storage.

3) Here are two specific examples:

The 16bit wide number of 0x1234 in Little-endian mode (and Big-endian mode) in CPU memory (assuming storage from address 0x4000) is:
Memory address Small Terminal mode storage content Store content in big-endian mode
0x4000 0x34 0x12
0x4001 0x12 0x34

32bit wide number of 0x12345678 in Little-endian mode and Big-endian mode) in CPU memory (assuming that the store starts from the address 0x4000) is:

Memory address Small Terminal mode storage content Store content in big-endian mode
0x4000 0x78 0x12
0x4001 0x56 0x34
0x4002 0x34 0x56
0x4003 0x12 0x78

C # code

intx =439041118;//16 binary to 1a2b3c5estrings =NULL;byte[] B =bitconverter.getbytes (x); s= Bitconverter.tostring (b);//Small terminal modeConsole.WriteLine (s);//small end output is 5e-3c-2b-1aArray.reverse (b);//reversals= Bitconverter.tostring (b);//Big- endian modeConsole.WriteLine ("{0:x}", s);//Big -endian output is 1a-2b-3c-5eConsole.readkey ();

C # small end to big Endian Little Endian

Related Article

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.