Reputation: 1817
How I can convert negative number into ASCII value?
I have to convert -1 ** into **ASCII value.
That means:
inputbyte[] = 0
output[] = -1
I did replacement like:
replacement 0 to -1 in string.
But I cant treat -1 as a number after represent string into Byte[]. I have to handle -1 as a single number like in integer.
Actually My original problem is:
input = "0110110111001000";
output should be = "-111-111-1111-1-11-1-1-1";
after that, I should be able to treat -1 and 1 as numbers i.e Byte.
How can I do that? thanks in advanced.
Upvotes: 0
Views: 2704
Reputation: 11920
I have to convert -1 ** into **ASCII value.
-1(signed char) equals to 127(unsigned char or ASCII value)
127 is DEL code in ASCII table.
To get an int from string:
Integer i = Integer.valueOf("-1");
|
|
here you put your sub-string of "-1"
Strring replacement:
String str="010100100011100011";
String result = str.replaceAll("0", "-1");
Big-integer to string:
String str=my_big_integer.toString();
Upvotes: 1