High Order and Low-order byte

rimalroshan picture rimalroshan · Nov 5, 2017 · Viewed 12.6k times · Source

The prototypes for getchar() and putchar() are:

int getchar(void);

int putchar(int c);

As ,its prototype shows, the getchar() function is declared as returning an integer.However, you can assign this value to a char variable, as is usually done, because the character is contained in the low-order byte.(The high-order byte is normally zero.)

Similary in case of putchar(),even though it is declared as taking an integer parameter you will generally call it using a character argument.Only the low order byte of its parameter is actually output to the screen.

What do you mean by high order and low order bytes?

Answer

user1118321 picture user1118321 · Nov 5, 2017

In C, the size of an int is implementation defined, but is usually 2, or 4 bytes in size. The high-order byte would be the byte that contains the largest portion of the value. The low-order byte would be the byte that contains the smallest portion of the value. For example, if you have a 16-bit int, and the value is 5,243, you'd write that in hex as 0x147B. The high order byte is the 0x14, and the low-order byte is the 0x7B. A char is only 1 byte, so it is always contained within the lowest order byte. When written in hex (in left-to-right fashion) the low-order byte will always be the right-most 2 digits, and the high-order byte will be the left-most 2 digits (assuming they write all the bytes out, including leading 0s).