hi everyone,
im working on a chat application project where the user can enter some text, this text goes into my compression algorithm which outputs a set of 8 bits with values from 0-255. I need to be able to take a value like 150 and change that into a string send it via TCP, recieve it on the other end and convert it back to 150.
so this is some code i have wrote to investigate:
int value = 150;
sendBytes[i] = (byte)value; //set char of byte
System.out.println("BYTE = " + (int)sendBytes[i]);
int rep = (int) sendBytes[0] & 0xFF;
System.out.println("REP = " + rep);
String test = new String(sendBytes,"UTF-8"); from the code above, i found that the number 150 when put into a byte will become a 2's complement number. so 128 will be -128.
the second statement "int rep = ..." will retrieve the original number..so if i say store value 128 in a byte..it will be stored as -128 but when i retrieve it with :
int rep = (int) sendBytes[0] & 0xFF;
System.out.println("REP = " + rep); i will get the number 128 back which is great!
now i need to be able to send the number -128 or the complement of 150 which is stored in the byte via TCP through a string. how can i do tht?