Computer byte size judgment, computer byte size

Source: Internet
Author: User
Tags erro

Computer byte size judgment, computer byte size

Recently I have been studying the computer interface technology and network programming basics. In these two disciplines, I have mentioned the problem of computer byte size-end judgment.

What is the size end?

If two consecutive addresses are empty, a + 1 is saved to an integer that occupies the two spaces. Take the sixteen-digit number as an example. 0x0102. If the value in a is 01, it indicates large-end storage. If the value in a is 02, it indicates small-end storage.

C language code:

# Include <stdio. h>
Union {
Short num;
Char num1 [sizeof (short)];
} Un;

Int main (int argc, char ** argv)

{
Un. num = 0x0102;
If (sizeof (short) = 2)
{
If (un. num1 [0] = 1 & un. num1 [1] = 2)
Printf ("big-endian ");
Else if (un. num1 [0] = 2 & un. num1 [1] = 1)
Printf ("little-andian ");
Else
Printf ("erro! ");
}
Else
Printf ("erro! ");

Return 0;

}

Assembly code implementation:

Include io32.inc
. Data
Msg1 byte 'big-endian ', 13, 10, 0
Msg2 byte 'little-endian ', 13, 10, 0

Num word 1234 h
. Code
Start:
Xor ebx, ebx
Mov bl, byte ptr num
; Mov eax, ebx
; Call dispuid
Cmp bl, 12 h
Je loop1
Mov eax, offset msg2

Jmp loop2

Loop1:
Mov eax, offset msg1
Loop2:
Call dispmsg

Exit 0
End start

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.