Number conversion host to big endian

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Number conversion host to big endian

跳至解决方案
2,707 次查看
jordi_becares
Contributor III

Hi,

I'm working on MKE1xF family over SDK2.5 and I'm looking for a solution for endian to host converter like htons().

My problem is that if I had a number and I want to convert to little/big endian, what is the method to use? The idea is use a common method for multiplatform, like htob (host to big endian) or htol (host to littel endian). In other platforms K60 MQX 4.1 there is support for this conversions


Is there any support for this family and SDK?

Thanks

Jordi

标签 (1)
标记 (2)
1 解答
2,611 次查看
jingpan
NXP TechSupport
NXP TechSupport

Hi Jordi,

There is some ARM function you can use.

__REV: Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.

For example:    A=__REV(B);     //A,B is 32bit variable

__REVSH: Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.

For example: C=__REVSH(D);   //C,D is 16bit variable

Regards,

Jing

在原帖中查看解决方案

2 回复数
2,612 次查看
jingpan
NXP TechSupport
NXP TechSupport

Hi Jordi,

There is some ARM function you can use.

__REV: Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.

For example:    A=__REV(B);     //A,B is 32bit variable

__REVSH: Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.

For example: C=__REVSH(D);   //C,D is 16bit variable

Regards,

Jing

2,611 次查看
jordi_becares
Contributor III

Hi Jing,

thanks for the feedback.

I didn't know this macros, and them are very useful.

Regards

Jordi

0 项奖励
回复