Em Andamento

Xor and Convert to Int Java Problem

I need to:

Read from a data stream and XOR with 0xFFFF. For example, the bytes:

f12a will convert to 3797

7f7b will convert to 32900

I am doing the following:

1. Read in a 2 byte data stream

2. Do an XOR with 0xFFFF

3. Convert to int

This is not producing the right answer. Code follows: (dis is DataInputStream)

byte[] OrigPort=new byte[2];

[url removed, login to view](OrigPort,0,2);

for (int i = 0; i < 2; i++)

{ OrigPort[i] ^= 0xFF;

}

long PortDecoded = BufferToInt(OrigPort);

//** Convert buffer to int */

public static long BufferToInt(byte[] x) {

long res = 0; int c = 0;

for (int i = 0; i < [url removed, login to view]; i ++)

{

int a = x[i];

a &= 0x000000FF;

a = a << c;

c += 8;

res |= a;

}

if (res < 0)

res &= 0x00000000FFFFFFFFL;

return res;

}

I need an answer to what I am doing wrong.

Habilidades: Java, Área de trabalho do Windows

Ver mais: java xor, java to c convert, int i, convert java to c, c for int, 0xff 0xff, 0xff, xor, java problem, int, data stream, convert to, convert to c, java code example, code example java, problem code java, convert java code, convert code java, data stream java, read code java, java code convert, java convert data, convert res, convert res res, java stream

Acerca do Empregador:
( 302 comentários ) Carmel Valley, United States

ID do Projeto: #3033406

Premiar a:

mrinalvenky

See private message.

$2 USD em 1 dia
(1 Comentário)
0.0

9 freelancers are bidding on average $4 for this job

mhmhz

See private message.

$5.1 USD em 1 dia
(116 Comentários)
6.4
wanly3643vw

See private message.

$5.1 USD em 1 dia
(38 Comentários)
4.4
soft1serve

See private message.

$3.4 USD em 1 dia
(19 Comentários)
3.4
zartheenumerator

See private message.

$4.25 USD em 1 dia
(3 Comentários)
3.1
hoangtuanbs

See private message.

$5.1 USD em 1 dia
(3 Comentários)
2.5
angelatwork

See private message.

$4.25 USD em 1 dia
(4 Comentários)
1.0
man5to6

See private message.

$4.25 USD em 1 dia
(1 Comentário)
0.0
ingali79

See private message.

$5.1 USD em 1 dia
(0 Comentários)
0.0