-2

I have used the following code. I just can't seem to get the value of x back from the byte array. Here is my code:

int seqNo = 0;
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(bout);
    try {
        out.writeInt(seqNo);
        String i = Integer.toString(seqNo) + "hello";
        byte[] b = i.getBytes();
        System.out.println(Arrays.toString(b));
        int x = b[0];
        System.out.println(x);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Here is the output:

[48, 104, 101, 108, 108, 111]
48

The output should contain 0 instead of 48. Please help

1 Answers1

0

48 is the ASCII code of 0

 int x=b[0]-48;
Mustapha Belmokhtar
  • 1,231
  • 8
  • 21