<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EmbLogic &#187; nitin.sharma</title>
	<atom:link href="https://www.emblogic.com/blog/author/nitin-sharma/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.emblogic.com/blog</link>
	<description>Embedded System and ARM Training</description>
	<lastBuildDate>Tue, 03 Mar 2020 13:00:06 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>Problem with bit wise operators</title>
		<link>https://www.emblogic.com/blog/04/problem-with-bit-wise-operators/</link>
		<comments>https://www.emblogic.com/blog/04/problem-with-bit-wise-operators/#comments</comments>
		<pubDate>Sun, 08 Apr 2012 07:01:59 +0000</pubDate>
		<dc:creator><![CDATA[nitin.sharma]]></dc:creator>
				<category><![CDATA[Data Structures with C]]></category>
		<category><![CDATA[BIT]]></category>
		<category><![CDATA[oprators]]></category>

		<guid isPermaLink="false">http://emblogic.org/blog/?p=2364</guid>
		<description><![CDATA[I am trying to pad two characters in num and trying to print the num in bit pattern.But I am getting -1 instead of 1; Output is for 65 &#8211; it should be 01000001 but i am getting 0-100000-1 sample &#8230; <a href="https://www.emblogic.com/blog/04/problem-with-bit-wise-operators/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I am trying to pad two characters in num and trying to print the num in bit pattern.But I am getting -1 instead of 1;<br />
Output is<br />
for 65 &#8211; it should be 01000001<br />
but i am getting 0-100000-1<br />
sample program is :-</p>
<p>/*padding ytwo char*/</p>
<p>#include&lt;stdio.h&gt;<br />
#include&lt;string.h&gt;<br />
#include&lt;stdlib.h&gt;</p>
<p>void char_pad();<br />
void bit_representation( int num);</p>
<p>int main()<br />
{<br />
char_pad();<br />
}<br />
void char_pad()<br />
{<br />
int num =0;<br />
char ch;<br />
printf(&#8220;enter first char :&#8221;);<br />
ch = getchar();<br />
num = num &lt;&lt; 8;<br />
num = num | ch;<br />
printf(&#8220;num is : %d\n&#8221;,num);<br />
while( getchar() != &#8216;\n&#8217;);</p>
<p>printf(&#8220;enter second char :&#8221;);<br />
ch = getchar();<br />
num = num &lt;&lt;8;<br />
num = num | ch;<br />
printf(&#8220;num is : %d\n&#8221;,num);<br />
bit_representation(num);<br />
}</p>
<p>void bit_representation( int num)<br />
{<br />
int temp,loc;<br />
int i,j;<br />
for(i=0; i&lt;4; i++)<br />
{<br />
temp = num;<br />
temp = temp &lt;&lt;(8 * i);</p>
<p>temp = temp &gt;&gt;(24)<br />
printf(&#8220;temp is : %d\n&#8221;,temp);<br />
for(j=0; j&lt;8; j++)<br />
{<br />
loc = temp;</p>
<p>loc = loc &lt;&lt; (24 +j);<br />
loc = loc &gt;&gt;31;<br />
printf(&#8220;%d&#8221;,loc);<br />
}<br />
printf(&#8220;\n&#8221;);<br />
}<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/04/problem-with-bit-wise-operators/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>FILE read and write</title>
		<link>https://www.emblogic.com/blog/04/2369/</link>
		<comments>https://www.emblogic.com/blog/04/2369/#comments</comments>
		<pubDate>Sun, 08 Apr 2012 06:59:00 +0000</pubDate>
		<dc:creator><![CDATA[nitin.sharma]]></dc:creator>
				<category><![CDATA[Data Structures with C]]></category>

		<guid isPermaLink="false">http://emblogic.org/blog/?p=2369</guid>
		<description><![CDATA[I am performing file read and write operations everything is working fine but my function is not checking EOF. It is not coming out of loop even if i had applied a condition (if character is equal to EOF ). &#8230; <a href="https://www.emblogic.com/blog/04/2369/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I am performing file read and write operations</p>
<p>everything is working fine but my function is not</p>
<p>checking EOF. It is not coming out of loop even if</p>
<p>i had applied a condition (if character is equal to EOF</p>
<p>).</p>
<p>&nbsp;</p>
<p>/*main file</p>
<p>File name : file_main.c*/</p>
<p>&nbsp;</p>
<p>#include&#8221;myheader.h&#8221;</p>
<p>int main(int argc,char *arg[])<br />
{<br />
int fptr,ch;<br />
fptr = open(arg[1],O_RDONLY);<br />
if(fptr == -1)<br />
{<br />
perror(&#8220;file does not exist \n&#8221;);<br />
exit(EXIT_FAILURE);<br />
}<br />
while(1)<br />
{<br />
printf(&#8220;press 1: to read 2: to copy to another file 3: to compress4: exit&#8221;);<br />
scanf(&#8220;%d&#8221;, &amp;ch);<br />
switch(ch)<br />
{<br />
case 1: read_file(fptr);<br />
break;<br />
case 2: copy_file(fptr);<br />
break;<br />
case 3: compress_file(fptr);<br />
break;<br />
case 4: exit(0);<br />
}<br />
}<br />
}</p>
<p>&nbsp;</p>
<p>/*file functions.c &#8212; function definitions are</p>
<p>present in this file*/</p>
<p>/* file name : file_functions.c*/</p>
<p>#include&#8221;myheader.h&#8221;</p>
<p>void read_file(int fptr)<br />
{<br />
char ch = &#8221;;<br />
int i;<br />
read(fptr,&amp;ch,1);<br />
while(1)<br />
{<br />
if(i != 0)<br />
{<br />
write(1,&amp;ch,1);<br />
}<br />
i = read(fptr,&amp;ch,1);<br />
if(ch == EOF)<br />
{<br />
printf(&#8220;******* FILE COMPLETE ********\n&#8221;);<br />
break;<br />
}<br />
}<br />
}</p>
<p>void copy_file(int fptr)<br />
{<br />
int file_d,i;<br />
char ch = &#8221;;<br />
file_d = open(&#8220;copy.txt&#8221;,O_CREAT | O_WRONLY);<br />
if(file_d == -1)<br />
{<br />
perror(&#8220;ERROR IN COPY FUNCTION : \n&#8221;);<br />
exit(EXIT_FAILURE);<br />
}<br />
while(1)<br />
{<br />
i = read(fptr,&amp;ch,1);<br />
if(i == 0)<br />
{<br />
continue;<br />
}<br />
if(ch == EOF)<br />
{<br />
break;<br />
}<br />
i = write(file_d,&amp;ch,1);<br />
while(i == 0)<br />
{<br />
i = write(file_d, &amp;ch,1);<br />
}<br />
}<br />
}</p>
<p>void compress_file(int fptr)<br />
{<br />
}</p>
<p>&nbsp;</p>
<p>/*make file */</p>
<p>FILE:file_functions.o file_main.o<br />
gcc -o FILE file_main.o file_functions.o<br />
file_main.o:file_main.c myheader.h<br />
gcc -g -c file_main.c<br />
file_functions.o:file_functions.c myheader.h<br />
gcc -g -c file_functions.c</p>
<p>clean:<br />
rm *.o<br />
rm FILE copy.txt</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/04/2369/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
