<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/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/"><channel><title>Problem Splitting Integer Variable</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/30345/problem-splitting-integer-variable</link><description> 
hi everyone... 

 
i am facing a problem in my college project... 

 
i have a 16bit unsigned integer variable and i need to store it in
the 24C02 EEPROM, but that saves 8bit variable at a time... 

 
the number i need to save is in the form of a decimal</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Problem Splitting Integer Variable</title><link>https://community.arm.com/thread/136754?ContentTypeID=1</link><pubDate>Tue, 17 Apr 2012 06:38:33 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ff0e7b56-b79c-47a2-8d3c-71a58d2d141a</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
He has never heard about Google, so the only way to get forward is
by asking on the net.&lt;/p&gt;

&lt;p&gt;
That the answers have already been written and published, making
Google searches a must faster route to progression, haven&amp;#39;t sunk in
yet...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Splitting Integer Variable</title><link>https://community.arm.com/thread/127466?ContentTypeID=1</link><pubDate>Tue, 17 Apr 2012 06:22:37 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:094d0a68-b316-48e5-b6f0-23a5b3d4b0a0</guid><dc:creator>&amp;#178;erik malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;but how do i use a union in this scenario&lt;/i&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Splitting Integer Variable</title><link>https://community.arm.com/thread/105934?ContentTypeID=1</link><pubDate>Mon, 16 Apr 2012 14:29:30 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5c8f786d-738f-4f5c-9c37-e02e3ad4fc69</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
With debugging, you would be able to take the value 0x1234 and
split and see yourself if you get 0x12 in one byte and 0x34 in
another byte.&lt;/p&gt;

&lt;p&gt;
Then you would know if you have an issue splitting, or if you have
an issue merging.&lt;/p&gt;

&lt;p&gt;
I&amp;#39;m not joking when I say you have to figure out how to verify
issues yourself. First when you do know something doesn&amp;#39;t work and
can&amp;#39;t figure out why is it meaningful to ask on a forum. But your
progress will be much higher if you do try to verify statements
yourself.&lt;/p&gt;

&lt;p&gt;
Integer promotion is that a 8-bit char is converted to &amp;quot;int&amp;quot;
first, before performing arithmetic on it. This is a requirement in
the C language. Cheap to do for a 16-bit or 32-bit processor, but
costly for an 8-bit processor where &amp;quot;int&amp;quot; is larger than any
register.&lt;/p&gt;

&lt;p&gt;
So Keil have optioned to generate non-standard code with C51
depending on compiler flags. This means that when you do a shift with
your 8-bit char, you shift out real bits into air. You not to
explicitly typecast to (unsigned int) before you do the shift, so you
have room to store your 8 &amp;quot;high&amp;quot; bits after the shift.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Splitting Integer Variable</title><link>https://community.arm.com/thread/80180?ContentTypeID=1</link><pubDate>Mon, 16 Apr 2012 14:00:42 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8aab79da-d67b-4023-a704-71262a8b0e20</guid><dc:creator>arun kumar</dc:creator><description>&lt;p&gt;&lt;p&gt;
i wanted to know if i was splitting them right&lt;/p&gt;

&lt;p&gt;
ubit_8 unsigned char&lt;br /&gt;
ubit_16 unsigned int&lt;/p&gt;

&lt;p&gt;
bit EEPROM24C02_Save_Data_8Bit(ubit_8 Data, ubit_8 Addr); //Data
is 8bit and Addr is a 8bit adress, return 1 when sucessful&lt;/p&gt;

&lt;p&gt;
bit EEPROM24C02_Read_Data_8Bit(ubit_8 Addr); // Adress to be read,
return 1 when sucessfull&lt;/p&gt;

&lt;p&gt;
what i am trying to do is split the integer into two Character
bytes and place them at location ADDR and ADDR+0x01, like Big Endian
method, (higher order at first and lower order at last)&lt;/p&gt;

&lt;pre&gt;
/*------------------------------------------------------------------*/
bit EEPROM24C02_Save_Data_16Bit(ubit_16 Data,ubit_8 ADDR)
{
        while(!(EEPROM24C02_Save_Data_8Bit&lt;b&gt;(((Data &amp;amp; 0xFF00)&amp;gt;&amp;gt;8)&lt;/b&gt;,ADDR)) &amp;amp;&amp;amp; (EEPROM24C02_Save_Data_8Bit&lt;b&gt;((Data &amp;amp; 0x00FF),ADDR+0x01)));&lt;/b&gt;
        return 1;


}
/*------------------------------------------------------------------*/
ubit_16 EEPROM24C02_Read_Data_16Bit(ubit_8 ADDR)
{
        ubit_16 Temp2=0;
                        Temp2|= EEPROM24C02_Read_Data_8Bit(ADDR);
                        Temp2&amp;lt;&amp;lt;=8;
                        Temp2|=EEPROM24C02_Read_Data_8Bit(ADDR+0x01);

                        return Temp2;
}
&lt;/pre&gt;

&lt;p&gt;
my main function is as follows to check these two functions&lt;/p&gt;

&lt;pre&gt;
void main()
{

        LCD_Initialize();
        EEPROM24C02_Save_Data_16Bit(1600,Load1_Page_SL);
        Convert_Num_Display_16bit(EEPROM24C02_Read_Data_16Bit(Load1_Page_SL));
        while(1);
}
&lt;/pre&gt;

&lt;p&gt;
1600(dummy value) is being shown as 1536 on the LCD,&lt;br /&gt;
The function&lt;br /&gt;
&lt;b&gt;Convert_Num_Display_16bit(ubit_16);&lt;/b&gt;&lt;br /&gt;
is correct, i have double checked it.. What is wrong with the code?
any corrections&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Splitting Integer Variable</title><link>https://community.arm.com/thread/127481?ContentTypeID=1</link><pubDate>Mon, 16 Apr 2012 13:37:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f72af111-d23b-42f5-a174-5c548c51ba75</guid><dc:creator>arun kumar</dc:creator><description>&lt;p&gt;&lt;p&gt;
what is integer promotion?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Splitting Integer Variable</title><link>https://community.arm.com/thread/116795?ContentTypeID=1</link><pubDate>Mon, 16 Apr 2012 13:15:08 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:9bafe88a-e641-49a0-8f71-067860b5b49c</guid><dc:creator>arun kumar</dc:creator><description>&lt;p&gt;&lt;p&gt;
yes i have heard of shift and would be using that method..&lt;/p&gt;

&lt;p&gt;
but how do i use a union in this scenario... can you explain with
an example&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Splitting Integer Variable</title><link>https://community.arm.com/thread/119673?ContentTypeID=1</link><pubDate>Mon, 16 Apr 2012 13:14:39 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:df74108a-9165-4b8c-9237-ce62ac09c88d</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
He has shifted - just that Keil don&amp;#39;t do integer promotion...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Splitting Integer Variable</title><link>https://community.arm.com/thread/105927?ContentTypeID=1</link><pubDate>Mon, 16 Apr 2012 13:09:06 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:abad19f7-cefd-4cf4-8fbb-bac6a98aa607</guid><dc:creator>&amp;#178;erik malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;sorry it was a typo when i was writing it in the forum it is
not&lt;/i&gt;&lt;br /&gt;
NEVER DO THAT, ALWAYS use cut-and-paste&lt;/p&gt;

&lt;p&gt;
there has been several threads that went on for ages with no
resolution because the posted code was not the code with the
peoblem.&lt;/p&gt;

&lt;p&gt;
re your original question;&lt;br /&gt;
have you heard of shift&lt;br /&gt;
have you heard of union&lt;br /&gt;
either will work&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Splitting Integer Variable</title><link>https://community.arm.com/thread/105932?ContentTypeID=1</link><pubDate>Mon, 16 Apr 2012 11:43:04 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b5306037-7d4d-4c6f-928b-cf03aa74defb</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
And have we then learned to not type code when only a copy from
your source code editor will guarantee that you get exactly the code
you are using?&lt;/p&gt;

&lt;p&gt;
1234 -&amp;gt; 1024 0000 0100 1101 0010 -&amp;gt; 0000 0100 0000 0000&lt;br /&gt;
6666 -&amp;gt; 6656 0001 1010 0000 1010 -&amp;gt; 0001 1010 0000 0000&lt;br /&gt;
5555 -&amp;gt; 5376 0001 0101 1011 0011 -&amp;gt; 0001 0101 0000 0000&lt;br /&gt;
1600 -&amp;gt; 1536 0000 0110 0100 0000 -&amp;gt; 0000 0110 0000 0000&lt;/p&gt;

&lt;p&gt;
See a pattern?&lt;/p&gt;

&lt;p&gt;
Where is your low byte?&lt;/p&gt;

&lt;p&gt;
What happens if you shift an 8-bit variable more than 8 bits?
Where will the data go if you haven&amp;#39;t first made sure there is room
for 16 bits?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Splitting Integer Variable</title><link>https://community.arm.com/thread/80179?ContentTypeID=1</link><pubDate>Mon, 16 Apr 2012 11:16:49 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:1dba4af0-e23f-4a71-b00c-bb581f9feea8</guid><dc:creator>arun kumar</dc:creator><description>&lt;p&gt;&lt;p&gt;
sorry it was a typo when i was writing it in the forum it is
not&lt;/p&gt;

&lt;pre&gt;
 b=val*0x00FF;
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
its&lt;/p&gt;

&lt;pre&gt;
b=val&amp;amp;0x00ff
&lt;/pre&gt;

&lt;p&gt;
the &amp;#39;*&amp;#39; and &amp;#39;&amp;amp;&amp;#39; are pretty close on keyboard&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Splitting Integer Variable</title><link>https://community.arm.com/thread/67410?ContentTypeID=1</link><pubDate>Mon, 16 Apr 2012 11:13:26 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ce46e0e2-4b5a-4065-9241-a3870b566838</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
&amp;quot;the number i need to save is in the form of a decimal
integer&amp;quot;&lt;/p&gt;

&lt;p&gt;
Not at all. The processor variables don&amp;#39;t store any decimal
integers. They just store numbers - it&amp;#39;s when you present the number
that you decide what numeric base to present it with.&lt;/p&gt;

&lt;p&gt;
b=(val * 0x00FF);&lt;/p&gt;

&lt;p&gt;
You have val (a 16-bit number) and you multiply with 255.&lt;/p&gt;

&lt;p&gt;
Take a suitable number - like 12345.&lt;br /&gt;
Convert to binary.&lt;br /&gt;
Perform a multiply by 255 and then try to convert that value to
binary.&lt;br /&gt;
Does it seem like it does what you want it to?&lt;/p&gt;

&lt;p&gt;
Doing the above is called debugging or validating. Proving if the
line does what you hope it should do. You would quickly come to a
conclusion - answering your question &amp;quot;is this code right?&amp;quot;.&lt;/p&gt;

&lt;p&gt;
And you would then also be able to figure out an answer to: &amp;quot;or is
there any other way?&amp;quot;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Splitting Integer Variable</title><link>https://community.arm.com/thread/60637?ContentTypeID=1</link><pubDate>Mon, 16 Apr 2012 10:52:59 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:76392ac7-5e23-4f9b-b44b-6b1a0dde9a38</guid><dc:creator>arun kumar</dc:creator><description>&lt;p&gt;&lt;pre&gt;
unsigned int Temp2=0;

---inside loop--
after each key press
Temp2*=10;
Temp2+=Keypress-&amp;#39;0&amp;#39;;
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>