Wednesday, April 9, 2014

Shift, bitwise OR operation? ? ?


RT
Newbie question ...

I have a button in the following operations:
 
Button btnClear = (Button) findViewById (R.id.btnClear);
btnClear.setOnClickListener (new Button.OnClickListener ()
{
@ Override
public void onClick (View v)
{
etMsgShow.setText ("");

byte [] bytes = new byte [2];
bytes [0] = (byte) 221;
bytes [1] = 7;
int i1 = (bytes [1] << 8);
int i2 = bytes [0];
int i = i1 | i2;
etMsgShow.append (
Integer.toString (i1) + ","
+ Integer.toString (i2) + ","
+ Integer.toString (i) + "\ r \ n");
}
}); / / BtnClear

Why is this information output:? ? ?



Why i is -35? ?
Phenomenon I want to achieve is the result of i 2013, how should I do? ? ?

ps: 221 ==> 0xDD; 2013 ==> 0x7DD.


<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
kao java complement binary form
Reply:
There is no Java primitive types unsigned type, byte int to be able to be replaced
Reply:
 int i1 = (bytes [1] << 8) & 0x0000ff00; 
int i2 = bytes [0] & 0x000000ff;

To do so.

No comments:

Post a Comment