src/main/java/com/osiris/maths/binary/Bits.java
/**
     * Converts the provided decimal number to {@link #bits} and returns it.
     * Note that negative numbers get converted to 2s complement and
     * the {@link #state} gets set accordingly.
     */
Converts the provided decimal number to  #bits and returns it.
Note that negative numbers get converted to 2s complement and
the  #state gets set accordingly.
Converts the provided decimal number to #bits and returns it . Note that negative numbers get converted to 2s complement and the #state gets set accordingly .
public static Bits from(int decimalNum, boolean printSteps) {
        if(printSteps) System.out.println("From "+decimalNum+" decimal to binary:");
        List<Bit> bits = new ArrayList<>();
        int quotient = decimalNum;
        if((""+decimalNum).contains("-")) quotient = Integer.parseInt((""+decimalNum).replace("-", ""));
        int remainder = 0;
        do {
            if (printSteps) System.out.print(quotient + "/2=");
            remainder = quotient % 2;
            if (remainder == 0) bits.add(new Bit(false));
            else bits.add(new Bit(true));
            quotient = quotient / 2;
            if (printSteps) System.out.println(quotient + "  r:" + remainder);
        } while (quotient != 0);
        Bits b = new Bits(bits, null, null);
        if((""+decimalNum).contains("-")) b.to(State.COMPLEMENT_2, printSteps);
        return b;
    }
public static Bits from ( int decimalNum , boolean printSteps ) { if ( printSteps ) System . out . println ( "From " + decimalNum + " decimal to binary:" ) ; List < Bit > bits = new ArrayList < > ( ) ; int quotient = decimalNum ; if ( ( "" + decimalNum ) . contains ( "-" ) ) quotient = Integer . parseInt ( ( "" + decimalNum ) . replace ( "-" , "" ) ) ; int remainder = 0 ; do { if ( printSteps ) System . out . print ( quotient + "/2=" ) ; remainder = quotient % 2 ; if ( remainder == 0 ) bits . add ( new Bit ( false ) ) ; else bits . add ( new Bit ( true ) ) ; quotient = quotient / 2 ; if ( printSteps ) System . out . println ( quotient + "  r:" + remainder ) ; } while ( quotient != 0 ) ; Bits b = new Bits ( bits , null , null ) ; if ( ( "" + decimalNum ) . contains ( "-" ) ) b . to ( State . COMPLEMENT_2 , printSteps ) ; return b ; }
Converts the provided decimal number to {@link #bits} and returns it.
Converts the provided decimal number to { @link #bits } and returns it .