MCPcopy Index your code
hub / github.com/careercup/ctci / main

Method main

java/Chapter 5/Sample_Code/Sample_Code.java:35–82  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

33 }
34
35 public static void main(String[] args) {
36
37 int number = 59;
38 System.out.println("Testing with number: " + number);
39
40 // Get Bit
41 System.out.println("Get Bit");
42 System.out.println(AssortedMethods.toFullBinaryString(number));
43 for (int i = 31; i >= 0; i--) {
44 int res = getBit(number, i) ? 1 : 0;
45 System.out.print(res);
46 }
47
48 // Update Bit
49 System.out.println("\n\nUpdate Bit");
50 int num1 = 1578; // arbitrary number
51 for (int i = 31; i >= 0; i--) {
52 int res = getBit(number, i) ? 1 : 0;
53 num1 = updateBit(num1, i, res);
54 }
55 System.out.println(num1);
56
57 // Set and Clear Bit
58 System.out.println("\nSet and Clear Bit");
59 int num2 = 1578; // arbitrary number
60 for (int i = 31; i >= 0; i--) {
61 if (getBit(number, i)) {
62 num2 = setBit(num2, i);
63 } else {
64 num2 = clearBit(num2, i);
65 }
66 }
67 System.out.println(num2);
68
69 // Clear Bits MSB through i
70 number = 13242352;
71 System.out.println("\nClear bits MSB through 4");
72 System.out.println(AssortedMethods.toFullBinaryString(number));
73 int num3 = clearBitsMSBthroughI(number, 4);
74 System.out.println(AssortedMethods.toFullBinaryString(num3));
75
76 // Clear Bits i through 0
77 System.out.println("\nClear bits 6 through 0");
78 number = -1;
79 System.out.println(AssortedMethods.toFullBinaryString(number));
80 int num4 = clearBitsIthrough0(number, 2);
81 System.out.println(AssortedMethods.toFullBinaryString(num4));
82 }
83
84}

Callers

nothing calls this directly

Calls 8

toFullBinaryStringMethod · 0.95
getBitMethod · 0.95
updateBitMethod · 0.95
setBitMethod · 0.95
clearBitMethod · 0.95
clearBitsMSBthroughIMethod · 0.95
clearBitsIthrough0Method · 0.95
printMethod · 0.45

Tested by

no test coverage detected