Number conversion host to big endian

cancel
Showing results for 
Search instead for 
Did you mean: 

Number conversion host to big endian

Jump to solution
174 Views
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

Labels (1)
Tags (2)
1 Solution
78 Views
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

View solution in original post

2 Replies
79 Views
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

View solution in original post

78 Views
Contributor III

Hi Jing,

thanks for the feedback.

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

Regards

Jordi

0 Kudos