Binary Digits : Binary Bit « Language Basics « Java






Binary Digits

  

/**
 * Template for standalone, line-mode main program.
 * @author Ian F. Darwin, http://www.darwinsys.com/
 * @version $Id: BinaryDigits.java,v 1.3 2004/02/09 03:33:56 ian Exp $
 */
public class BinaryDigits {
  public static void main(String[] argv) {
    //+
    String bin = "101010";
    System.out.println(bin + " as an integer is " + Integer.valueOf(bin, 2));
    int i = 42;
    System.out.println(i + " as binary digits (bits) is " + 
      Integer.toBinaryString(i));
    //-
  }
}


           
         
    
  








Related examples in the same category

1. Utility for byte swapping of all java data types
2.Bitwise DemoBitwise Demo
3.Using the bitwise operatorsUsing the bitwise operators
4.Bitwise complement (~): inverts ones and zeroes in a number
5.Convert a number to negative and back
6.Bitwise AND (&)
7.Bitwise OR (|)
8.Bitwise XOR (^)
9.Left shift (<<)
10.Performing Bitwise Operations on a Bit Vector
11.Converting Between a BitSet and a Byte Array
12.Returns a byte array of at least length 1
13.Shift to the left
14.Signed shift to the right
15.Unsigned shift to the right
16.Bit-level unpacking of floating-point data
17.Gets the a single bit of the target.
18.Returns 16 bits from the long number.
19.Sets a specific bit of an int.
20.Fuses the lower 16 bits of two ints.
21.Class to represent unsigned 32-bit numbers.
22.A list of bits.
23.Gets the specified bit (0-31) from the integer argument.
24.Sets the specified bit (0-31) in the integer argument.
25.Clears a range of bits in the specified integer.