473,378 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

bit-shift doesn't produce expected 0!

After running this:

unsigned long long x = (unsigned long long)-1;
int y = 64;
x = x >y;

the value of x is 0xffffffffffffffff though I'd have expected 0. Strangely,
shifting by 63 produces 1 as expected. Any idea what's up with that?

I'm using gcc 4.0.2 if that's relevant.
Dec 12 '06 #1
2 1359
fizzleBomb wrote:
After running this:

unsigned long long x = (unsigned long long)-1;
int y = 64;
x = x >y;

the value of x is 0xffffffffffffffff though I'd have expected 0.
Strangely, shifting by 63 produces 1 as expected. Any idea what's up with
that?
Undefined behavior [5.8/1]:

The shift operators << and >group left-to-right.
[...]
The operands shall be of integral or enumeration type and integral
promotions are performed. The type of the result is that of the promoted
left operand. The behavior is undefined if the right operand is negative,
or greater than or equal to the length in bits of the promoted left
operand.
I'm using gcc 4.0.2 if that's relevant.
It isn't.
Best

Kai-Uwe Bux
Dec 12 '06 #2
Kai-Uwe Bux wrote:
Undefined behavior [5.8/1]:

The shift operators << and >group left-to-right.
[...]
The operands shall be of integral or enumeration type and integral
promotions are performed. The type of the result is that of the promoted
left operand. The behavior is undefined if the right operand is
negative, or greater than or equal to the length in bits of the promoted
left operand.
>I'm using gcc 4.0.2 if that's relevant.

It isn't.
Best

Kai-Uwe Bux
Thanks much!
Dec 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Bonj | last post by:
Happy new year to everybody... Just a few questions about porting code to 64-bit environment. 1) Is there a different version of the SDK (i.e., C/C++ compiler) for the 64-bit platform, or does...
2
by: Skybuck Flying | last post by:
Hi, I think I might have just invented the variable bit cpu :) It works simply like this: Each "data bit" has a "meta data bit". The meta data bit describes if the bit is the ending bit...
13
by: Amy DBA | last post by:
I've been asked to administer a DB2 V 8 (32-bit install) on a Solaris 64-bit platform. It seems like whomever installed DB2 on the server, goofed for not installing DB2 v8 64 bit. Do I understand...
12
by: Jean-Marc Blaise | last post by:
Hi, Is it worth to use 64-bit DB2 instances on a 32-bit kernel, in terms of: - performance - configuration (go beyond the 256 Mb segment for private mem, 1.75 Gb for Bufferpools) - other ? ...
16
by: Mohanasundaram | last post by:
Hi All, We are working on porting a product written in C and C++ from 32 bit to 64 bit. We need to maintain both 32 bit and 64 bit versions in the future. We took the 32 bit source code and...
112
by: Carsten Hansen | last post by:
Suppose I'm using an implementation where an int is 16 bits. In the program below, what function is called in the first case, and what is called in the second case? Also, if there is a difference...
11
by: JDeats | last post by:
1. Will there be different 64-bit .NET implementations for Intel and AMD 64-bit processors or will they share a common 64-bit CLR? 2. Will .NET managed code compiled for the 32-bit CLR be binary...
2
by: Avi Laviad | last post by:
hi, sorry for the dumb question but how do i code a bit variable in c? i mean - shoudlnt the synax need to be: bit j; j = 1; correct me if im wrong (and i suppose i am). Avi.
4
by: tommydkat | last post by:
Well, I've finally gotten UDB 8.2 FixPak 3 up and running on my HP-UX 11i system, thanks to Mr McBride and IBM support. :) I created a 32-bit instance and that's running just fine. However, I...
14
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I am using C# to develop DLL using Visual Studio 2005 and .Net 2.0, and I have no idea of how to make my DLL work with applications on 64-bit platform. Above all, I do not...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.