Chris_45
Chris_45

Reputation: 9043

How to convert a String in java with 1s and 0s to corresponding ASCII value?

How do one convert a String in java with 1 and 0s to corresponding ASCII value?

Lets say I have

String str = "01101110";

How do I convert it to be its corresponding 'n' so I can print n?

System.out.printl(str.toCorrespondingAscii());//output n

Upvotes: 0

Views: 667

Answers (1)

nebula
nebula

Reputation: 3982

int value = Integer.parseInt("01101110", 2); //2 for binary
System.out.println(value);  // To print ascii

char digit = (char) value;
System.out.println(digit);  // To print n

Upvotes: 3

Related Questions