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:  
  10101010
Converted to Int:     
  11111111111111111111111110101010
Shift Int by 4:       
  00001111111111111111111111111010
New Byte (-6):        
  11111010
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


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

 

 

About | Sitemap | Contact