Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -2,29 +2,29 @@ import java.util.List;
|
|||
|
||||
public final class TwosComplement {
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Integer> examples = List.of( 0, 1, -1, 42 );
|
||||
|
||||
System.out.println(String.format("%9s%12s%24s%34s", "decimal", "hex", "binary", "two's complement"));
|
||||
System.out.println(
|
||||
public static void main(String[] args) {
|
||||
List<Integer> examples = List.of( 0, 1, -1, 42 );
|
||||
|
||||
System.out.println(String.format("%9s%12s%24s%34s", "decimal", "hex", "binary", "two's complement"));
|
||||
System.out.println(
|
||||
String.format("%6s%12s%24s%32s", "-----------", "--------", "----------", "----------------"));
|
||||
|
||||
for ( int example : examples ) {
|
||||
System.out.println(String.format("%5d%18s%36s%13d",
|
||||
|
||||
for ( int example : examples ) {
|
||||
System.out.println(String.format("%5d%18s%36s%13d",
|
||||
example, toHex(example), toBinary(example), twosComplement(example)));
|
||||
}
|
||||
}
|
||||
|
||||
private static String toHex(int number) {
|
||||
return String.format("%8s", Integer.toHexString(number).toUpperCase()).replace(" ", "0");
|
||||
}
|
||||
|
||||
private static String toBinary(int number) {
|
||||
return String.format("%32s", Integer.toBinaryString(number)).replace(" ", "0");
|
||||
}
|
||||
|
||||
private static int twosComplement(int number) {
|
||||
return ~number + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String toHex(int number) {
|
||||
return String.format("%8s", Integer.toHexString(number).toUpperCase()).replace(" ", "0");
|
||||
}
|
||||
|
||||
private static String toBinary(int number) {
|
||||
return String.format("%32s", Integer.toBinaryString(number)).replace(" ", "0");
|
||||
}
|
||||
|
||||
private static int twosComplement(int number) {
|
||||
return ~number + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue