<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>NTON function not available in SDK17</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/74715/nton-function-not-available-in-sdk17</link><description>Hi, 
 I am trying to convert a number from little endian to big endian. There is a built in function &amp;quot;NTON&amp;quot; that I can use instead of writing my own code, but I can not find it in nrf52840 SDK17. 
 I am using Keil as IDE. The example code that I am using</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 04 May 2021 01:57:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/74715/nton-function-not-available-in-sdk17" /><item><title>RE: NTON function not available in SDK17</title><link>https://devzone.nordicsemi.com/thread/308036?ContentTypeID=1</link><pubDate>Tue, 04 May 2021 01:57:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:487a2a50-ee79-460d-85cf-da3b310098ec</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Have a look at &lt;em&gt;endian.h&lt;/em&gt;; to convert from little-endian (silly order) to big endian (sensible order) that header provides the conversion functions:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#ifndef __machine_host_to_from_network_defined
#if _BYTE_ORDER == _LITTLE_ENDIAN
#define	__htonl(_x)	__bswap32(_x)
#define	__htons(_x)	__bswap16(_x)
#define	__ntohl(_x)	__bswap32(_x)
#define	__ntohs(_x)	__bswap16(_x)
#else
#define	__htonl(_x)	((__uint32_t)(_x))
#define	__htons(_x)	((__uint16_t)(_x))
#define	__ntohl(_x)	((__uint32_t)(_x))
#define	__ntohs(_x)	((__uint16_t)(_x))
#endif
#endif /* __machine_host_to_from_network_defined */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;endian.h&lt;/em&gt; is here (example, depends on compiler used in SES or Keil):&lt;/p&gt;
&lt;p&gt;&lt;em&gt;C:\program files (x86)\gnu tools arm embedded\9 2019-q4-major\arm-none-eabi\include\machine\endian.h&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static __inline __uint16_t __bswap16(__uint16_t _x)
{
	return ((__uint16_t)((_x &amp;gt;&amp;gt; 8) | ((_x &amp;lt;&amp;lt; 8) &amp;amp; 0xff00)));
}

static __inline __uint32_t __bswap32(__uint32_t _x)
{
	return ((__uint32_t)((_x &amp;gt;&amp;gt; 24) | ((_x &amp;gt;&amp;gt; 8) &amp;amp; 0xff00) |
	    ((_x &amp;lt;&amp;lt; 8) &amp;amp; 0xff0000) | ((_x &amp;lt;&amp;lt; 24) &amp;amp; 0xff000000)));
}

static __inline __uint64_t __bswap64(__uint64_t _x)
{
	return ((__uint64_t)((_x &amp;gt;&amp;gt; 56) | ((_x &amp;gt;&amp;gt; 40) &amp;amp; 0xff00) |
	    ((_x &amp;gt;&amp;gt; 24) &amp;amp; 0xff0000) | ((_x &amp;gt;&amp;gt; 8) &amp;amp; 0xff000000) |
	    ((_x &amp;lt;&amp;lt; 8) &amp;amp; ((__uint64_t)0xff &amp;lt;&amp;lt; 32)) |
	    ((_x &amp;lt;&amp;lt; 24) &amp;amp; ((__uint64_t)0xff &amp;lt;&amp;lt; 40)) |
	    ((_x &amp;lt;&amp;lt; 40) &amp;amp; ((__uint64_t)0xff &amp;lt;&amp;lt; 48)) | ((_x &amp;lt;&amp;lt; 56))));
}&lt;/pre&gt;&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>