Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A small problem on bits 1

Status
Not open for further replies.

sachindn

Programmer
Jun 27, 2000
10
US
Dear friend,
If i write
unsigned char c;
c=2;
printf(&quot;The value after bit shift is %d&quot;,(c<<16);

Is it a valid syntax will i get an exact answer?
I am getting zero for this why??
As I am not storing this value to any other variable i must get the correct answer for printf but I am not getting why??
Plz answer me
regards

 
unsigned char c=2; &quot;00000010&quot; 8 bit only

if you use
printf(&quot;Value: %d&quot;,c<<16);
you have &quot;Value: 131072&quot;
(2 in degree of 17)

but if you use:
c=c<<16;
printf(&quot;Value: %d&quot;,c<<16);
You have &quot;Value: 0&quot;

Because unsigned char is only 8 bit.
c=c<<16=000000100000000000000000 = 00000000 = 0
Regards, Lim.
P.S. Y have syntax error in your message, one extra &quot;(&quot;.
 
Sorry in last printf should be
printf(&quot;Value: %d&quot;, c);
Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top