Why doesn't performing an unsigned right shift on a negative byte shift in 0's instead of 1's?

John Zukowski

Java promotes all numeric operands to at least an int before performing the operation. Thus, right shifting will shift in zero's into the high order byte of the int, not in the right most lower order byte where needed. Thus, your result will still be a negative number.

Original Byte:  
Converted to Int:     
Shift Int by 4:       
New Byte (-6):        
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact