<?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>Representation of 24-bit and 40 bit values</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/47739/representation-of-24-bit-and-40-bit-values</link><description>Hi, 
 I am trying to develop models using the Specifications. I came across generic battery model which was using 24-bit values, time model which was using 15-bit and 40-bit values, scheduler model uses 4-bit and 76 bit values. 
 In the stdint.h, there</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 28 May 2019 22:27:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/47739/representation-of-24-bit-and-40-bit-values" /><item><title>RE: Representation of 24-bit and 40 bit values</title><link>https://devzone.nordicsemi.com/thread/189724?ContentTypeID=1</link><pubDate>Tue, 28 May 2019 22:27:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aeef5c93-4bdc-4cde-b249-890f18c628ce</guid><dc:creator>awneil</dc:creator><description>[quote userid="74350" url="~/f/nordic-q-a/47739/representation-of-24-bit-and-40-bit-values/189720"]do you mean to define it as a structure[/quote]
&lt;p&gt;Or an array.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Representation of 24-bit and 40 bit values</title><link>https://devzone.nordicsemi.com/thread/189720?ContentTypeID=1</link><pubDate>Tue, 28 May 2019 21:46:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8320138b-1838-417e-8a28-c75e9aad521e</guid><dc:creator>DeveloperZ</dc:creator><description>[quote userid="6462" url="~/f/nordic-q-a/47739/representation-of-24-bit-and-40-bit-values/189717"]but you could use 3 bytes, if you like.[/quote]
&lt;p&gt;By this, do you mean to define it as a structure as he said above or is there any other way to define a variable of size 24-bits?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Representation of 24-bit and 40 bit values</title><link>https://devzone.nordicsemi.com/thread/189717?ContentTypeID=1</link><pubDate>Tue, 28 May 2019 21:25:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:60895f7d-8fca-4e6c-b4c4-bcd7e04843b7</guid><dc:creator>awneil</dc:creator><description>[quote userid="73680" url="~/f/nordic-q-a/47739/representation-of-24-bit-and-40-bit-values/189710"]15-bit; should I use 16-bit[/quote]
&lt;p&gt;Well, you can&amp;#39;t use less than 16.&lt;/p&gt;
&lt;p&gt;Being a 32-bit architecture, using 16 against 32 may not gain you much.&lt;/p&gt;
[quote userid="73680" url="~/f/nordic-q-a/47739/representation-of-24-bit-and-40-bit-values/189710"]for 24-bit; should I use 32-bit?[/quote]
&lt;p&gt;That&amp;#39;ll be easiest - but you could use 3 bytes, if you like.&lt;/p&gt;
[quote userid="73680" url="~/f/nordic-q-a/47739/representation-of-24-bit-and-40-bit-values/189710"]40-bit; should I use 64-bit[/quote]
&lt;p&gt;Again, 64 will be easiest, but 5 bytes would do it.&lt;/p&gt;
[quote userid="73680" url="~/f/nordic-q-a/47739/representation-of-24-bit-and-40-bit-values/189710"]and specify the limits[/quote]
&lt;p&gt;Not sure what you mean by that?&lt;/p&gt;
[quote userid="73680" url="~/f/nordic-q-a/47739/representation-of-24-bit-and-40-bit-values"]should I define the limits in the stdint.h [/quote]
&lt;p&gt;You should not fiddle with stdint.h.&lt;/p&gt;
&lt;p&gt;If you want custom types, then create a custom header...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Representation of 24-bit and 40 bit values</title><link>https://devzone.nordicsemi.com/thread/189710?ContentTypeID=1</link><pubDate>Tue, 28 May 2019 18:20:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29ca4581-9112-457f-8d2b-881cfa7995f3</guid><dc:creator>Aryan</dc:creator><description>&lt;p&gt;Thanks for the detailed explanation.&lt;/p&gt;
&lt;p&gt;For the other sizes like 15-bit; should I use 16-bit?&lt;/p&gt;
&lt;p&gt;for 24-bit; should I use 32-bit?&lt;/p&gt;
&lt;p&gt;&lt;span&gt;for 40-bit; should I use 64-bit?&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;and specify the limits?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Representation of 24-bit and 40 bit values</title><link>https://devzone.nordicsemi.com/thread/189275?ContentTypeID=1</link><pubDate>Mon, 27 May 2019 11:00:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4c6889f-a285-411f-b510-41b9b976aad1</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Aryan&lt;/p&gt;
&lt;p&gt;You can&amp;#39;t create variables with a different size than the basic types (8, 16, 32 or 64), but you can create structs that contain arbitrarily sized fields (up to 64 bits maximum) by using &lt;a href="https://www.tutorialspoint.com/cprogramming/c_bit_fields.htm"&gt;bit fields&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For the 76-bit value you mention this would look something like this:&lt;/p&gt;
&lt;p&gt;typedef struct __PACKED&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; uint32_t year : 7;&lt;br /&gt;&amp;nbsp; uint32_t month : 12;&lt;br /&gt;&amp;nbsp; uint32_t day : 5;&lt;br /&gt;&amp;nbsp; uint32_t hour : 5;&lt;br /&gt;&amp;nbsp; uint32_t minute : 6;&lt;br /&gt;&amp;nbsp; uint32_t second : 6;&lt;br /&gt;&amp;nbsp; uint32_t day_of_week : 7;&lt;br /&gt;&amp;nbsp; uint32_t action : 4;&lt;br /&gt;&amp;nbsp; uint32_t transition_time : 8;&lt;br /&gt;&amp;nbsp; uint32_t scene_number : 16;&lt;br /&gt;} schedule_register_t;&lt;/p&gt;
&lt;p&gt;The __PACKED tag ensures that the struct is byte aligned, rather than 16 or 32 bit aligned, to keep the size in memory as small as possible.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please be aware that the size of the struct will be 80 bits (10 bytes), and not 76, since the minimum alignment for any struct or variable is 1 byte.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>