Re: [Dev-C++] Shift operators portability
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Michael D. S. <for...@hi...> - 2003-09-23 04:37:54
|
No wraparound, they drop off the end, at least on any machine I've ever
been familiar with.
I thought I would try, see how it works on this machine and got nothing. No
compiler error, and no change in the int.
Anyone know why this produces nothing (16) every time? And I tried other
numbers, in both positions, as well. Even tried turning it around -- Same
thing, nothing, every time. It seems there should be some effect, or an
error..
I have an AMD processor and no idea if it's big or little endian.
#include<iostream.h>
#include<stdlib.h>
#include<fstream.h>
int main()
{
int count = 16;
count >> 2;
cout << "count = " << count << "\n";
2 << count;
cout << "count = " << count << "\n";
system ("pause");
return 0;
}
At 08:14 PM 9/22/03, you wrote:
>Hi there.
>
>Are the shift operators ( << and >> ) portable?
>i.e.
>Does x << 1 have the same effect as multiplying by 2 ?
>and
>Does x >> 1 have the same effect as dividing by 2?
>On both big and little endian order machines?
>
>also is there any wraparound?
>i.e. in a shift the bits that are pushed out of the data structure placed
>at the back-end of the data structure (on the other side of where they
>were pushed out)?
>
>Thanks in Advance
>David McKen
>
>
>Do you Yahoo!?
><http://us.rd.yahoo.com/evt=10469/*http://sitebuilder.yahoo.com>Yahoo!
>SiteBuilder - Free, easy-to-use web site design software
|