-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShiftInt.java
More file actions
36 lines (30 loc) · 1.24 KB
/
ShiftInt.java
File metadata and controls
36 lines (30 loc) · 1.24 KB
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
27
28
29
30
31
32
33
34
35
36
package com.dj;
public class ShiftInt {
private static final String ANSI_RESET = "\u001B[0m";
private static final String ANSI_BLACK = "\u001B[30m";
private static final String ANSI_RED = "\u001B[31m";
private static final String ANSI_GREEN = "\u001B[32m";
private static final String ANSI_YELLOW = "\u001B[33m";
private static final String ANSI_BLUE = "\u001B[34m";
private static final String ANSI_PURPLE = "\u001B[35m";
private static final String ANSI_CYAN = "\u001B[36m";
private static final String ANSI_WHITE = "\u001B[37m";
public static void main(String[] args) {
int x = 922342959;
writeInt(x);
}
private static void display(int x) {
String all = String.format("%32s", Integer.toBinaryString(x)).replace(" ", "0");
String colouredBinary = all.substring(0, 24) + ANSI_PURPLE + all.substring(24) + ANSI_RESET;
int y = x & 0xFF;
String output = String.format("%10d and 0xFF is %8s \t %10d is ", y, Integer.toBinaryString(y), x) + colouredBinary;
System.out.println(output);
}
private static void writeInt(int v) {
int x;
display(v >>> 24);
display(v >>> 16);
display(v >>> 8);
display(v >>> 0);
}
}