-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharToBin.java
More file actions
26 lines (20 loc) · 951 Bytes
/
CharToBin.java
File metadata and controls
26 lines (20 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class CharToBin {
public static void main(String[] args) {
char ch1 = 'A';
char ch2 = '5';
int num1 = (int) ch1;
int num2 = (int) ch2;
System.out.println("Numeric value of " + ch1 + " is " + num1);
System.out.println("Numeric value of " + ch2 + " is " + num2);
char asciiChar1 = (char) num1;
char asciiChar2 = (char) num2;
System.out.println("Char of " + num1 + " is " + asciiChar1);
System.out.println("Char of " + num2 + " is " + asciiChar2);
String binary = Integer.toBinaryString(num1);
System.out.println(binary);
System.out.println("Binary representation of " + num1 + " is: " + binary);
System.out.println("Make sure to convert to 8 bits!");
int number = Integer.parseInt("01000001", 2);
System.out.println("Integer value of binary " + binary + " is: " + number);
}
}