您的位置:首页 > 产品设计 > UI/UE

Binary Expression and Value Expression

2016-03-06 16:12 387 查看

Hi guys

My Email: jakezhang1989@hotmail.com

My GitHub Link

Thank you for taking time to go through this post from which you would get what you want.

If you have any problems or opinions that are different form mins, please email me or leave a comments. I will reply as soon as possible.

OK, Let us get started!

Glossory

HMA : High Memory Address

LMA : Low Memory Address

HB : High Byte

LB : Low Byte

Little endian : a HB is stored in HMA, a LB is stored at LMA

Big endian: a HB is stored in LMA, a LB is stored at HMA

Topic

This blog is to highlight a misunderstanding I used to have that I mixed up the binary expression and value expression regarding to endian swap

Argument

Binary expression is a format used to store a variable in memory whereas value expression is the human-readable values that represents.

Supporting Statements

Say we have (other types follow the same rules)

short a = 128;

Its value expression may look like this:

HB<- - - - - - - - LB

00000000 10000000

{highbyte} {lowbyte}

Its little endian binary expression may look like this:

LMA- - - - - - - - - ->HMA

{lowbyte} {highbyte}

10000000 00000000

Its big endian binary expression may look like this:

LMA- - - - - - - - - ->HMA

{highbyte} {lowbyte}

00000000 10000000

Take the example of little endian a above, I used to think that little endian a has a decimal value of 2^15 as bit 1 is at the index of 15, which should have been decimal value of 128.

Actually, the correct way to represent the value of little endian a by little endian CPU is based on the fact that CPU will always obtain the value expression from binary expression and the value of a variable we often talk about actually points out the value expression (10 base, binary base or 8 base):

When CPU meets the first byte 100000, it knows this byte should be low byte in value expression since the byte is stored in LMA. And the second byte 000000 should be the high byte in value expression. So, the final binary base value expression should be 00000000 10000000, and its decimal value is therefore 2^8 that equals to one we assigned before.

End of the post.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: