Binary Expression and Value Expression

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值