C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28695
Number of posts: 94715

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
bitwise left shift operator Posted by snsuma on 3 Oct 2012 at 10:03 AM
hi
if we left shift 35 by 4 places, we are supposed to get result ( 35 x 2 to the power 4 ) according to definition of left shift operator but I am getting a different answer. why?

binary of 35 is 00100011
00100011 << 4 will result in 00110000 which is 48 where as the result should be 35 x 16 = 560.

please somebody help me
Report
Re: bitwise left shift operator Posted by WaltP on 5 Oct 2012 at 12:53 PM
If your value is in a byte (char) you loose all the bits above 255. So 35 (00100011) becomes 48 (00110000)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.