Re: 8 bit binary to ascii
You can convert each set of 8 back into a number and then put that value directly into a byte data type (some casting required). To convert between bases: See WikiHow: Convert from binary to decimal
The biggest issue is that the values you have are in ASCII, while the char data type is Unicode. Technically you won't see this crop up if you just want to get those ASCII values back, but it's possible that if you try to display these values you will get the wrong characters displayed. See Java: Converting Non-Unicode Text for information on converting non-unicode characters into unicode.
Re: 8 bit binary to ascii
Hi
If I were you I would convert that Binary into String by using following code. If you find any other best way let me know.
Code :
int power;
double val;
int asval;
String s2=" ";
for(int i=0;i<5;i++)
{
power=-1;
asval=0;
for(int j=7;j>=0;j--)
{
power++;
val=0;
if(arr[i][j]==1)
{
val=Math.pow(2,power);
asval += (int)(val);
}
}
s2=s2+(char)(asval);
}
s2=s2.substring(1);
System.out.println(s2);
Re: 8 bit binary to ascii
hi,
thanks for the post. i have run the code but it didn't work.
say if i put string as "hi" it will print 0110100001101001.
and how i'm gonna convert it back?
Re: 8 bit binary to ascii
consider a to z, 0 to 25 and store the bit pattern in the corresponding array (the first index). Suppose a[2][] will contain pattern for c, u will search the array if match found add 97 to its index. A very naive approach, slow....
Re: 8 bit binary to ascii