right shift math errors: 1>>32 = 1

Bug #601266 reported by thearthur
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
openjdk-6 (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

the right shift operator produces wrong results when shifting ints by 32 bits.

Description: Ubuntu 9.04
Release: 9.04

 openjdk-6-jre 6b14-1.4.1-0ubuntu13

Linux cryptovide-dev 2.6.28-18-generic #60-Ubuntu SMP Fri Mar 12 04:26:47 UTC 2010 x86_64 GNU/Linux

java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.4.1) (6b14-1.4.1-0ubuntu13)
OpenJDK 64-Bit Server VM (build 14.0-b08, mixed mode)

class Tmp {
    public static void main(String[] args) {
        System.out.println("1>>1 = "+(1>>1));
        System.out.println("1>>2 = "+(1>>2));
        System.out.println("1>>31 = "+(1>>31));
        System.out.println("1>>32 = "+(1>>32));
        System.out.println("1>>33 = "+(1>>33));
    }
}

1>>1 = 0
1>>2 = 0
1>>31 = 0
1>>32 = 1 <---------- should be 0
1>>33 = 0

Revision history for this message
thearthur (arthur-ulfeldt) wrote :

not actually a bug: the java spec specifies that only the last five bits of the second argument are used.

Changed in openjdk-6 (Ubuntu):
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.