BHere’s the code:
c#
private void button1_Click(object sender, EventArgs e)
{
int a = -33554432;
byte b = (byte)(a >> 24);
MessageBox.Show(b.ToString());
}
java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int a = -33554432;
byte b = (byte)(a >> 24);
JOptionPane.showMessageDialog(null, Byte.toString(b));
}
I’ve read around this problem, and I believe there is a relatively simple way of understanding the different behavior, but I need a little help in reaching this understanding. Any takers, please?
Many thanks!
EDIT: ok, now using Byte.toString(). Output for c# = 254 java = -2
Byte in Java is a signed value. In this case you could actually just use:
Alternatively: