//  Copyright 2016 The Minorminor Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package jdk7;

public class BitOperation {
    /**
     * @param input int number
     * @return  binary string with 32 length
     */
    public static String bitFormat(int input) {
        String in = Integer.toBinaryString(input);
        if (32 - in.length() > 0)
            return String.format("%0" + (32 - in.length()) + "d%" + in.length() + "s", 0, in);
        return in;
    }
}

@@ -721,16 +721,50 @@
  string 
+in the format of two's complement 
 with 32 
@@ -805,17 +805,20 @@
 tring bi
-t
+nary
 Format(i
@@ -829,16 +829,614 @@
 nput) %7B%0A
+        // Java using two's complement to represent binary number. (sign-and-magnitude, ones' complement, two's complement, excess-N)%0A        // the left first bit is sign bit.%0A        // for positive integer, sign-and-magnitude= ones' complement= two's complement%0A        // for negative integer, except the sign bit, two's complement = its Absolute value's ones' complement +1.%0A%0A        // for 8 bytes integer scope is %5B1111 1111 , 0111 1111%5D, its %5B-127 , 127%5D%0A        // 0 is%5B0000 0000%5D and %5B1000 0000%5Dis -128,%0A        // involve the sign bit in computing and let subtraction becomes addition.%0A%0A
         

Add comments to BitOperation.binaryFormat()