List of usage examples for java.lang Integer toBinaryString
public static String toBinaryString(int i)
From source file:com.mycompany.mavenproject1.Ex1.java
public static void main(String[] args) { Ex1 obj = new Ex1(); String data = obj.getFileWithUtil("data.json"); for (int i = 0; i < data.length(); i++) { System.out.println(Integer.toBinaryString(data.charAt(i))); }// w w w. j ava 2 s. c o m }
From source file:org.apache.commons.net.examples.cidr.SubnetUtilsExample.java
public static void main(String[] args) { String subnet = "192.168.0.3/31"; SubnetUtils utils = new SubnetUtils(subnet); SubnetInfo info = utils.getInfo();/*from w w w . j a v a2s.c o m*/ System.out.printf("Subnet Information for %s:%n", subnet); System.out.println("--------------------------------------"); System.out.printf("IP Address:\t\t\t%s\t[%s]%n", info.getAddress(), Integer.toBinaryString(info.asInteger(info.getAddress()))); System.out.printf("Netmask:\t\t\t%s\t[%s]%n", info.getNetmask(), Integer.toBinaryString(info.asInteger(info.getNetmask()))); System.out.printf("CIDR Representation:\t\t%s%n%n", info.getCidrSignature()); System.out.printf("Supplied IP Address:\t\t%s%n%n", info.getAddress()); System.out.printf("Network Address:\t\t%s\t[%s]%n", info.getNetworkAddress(), Integer.toBinaryString(info.asInteger(info.getNetworkAddress()))); System.out.printf("Broadcast Address:\t\t%s\t[%s]%n", info.getBroadcastAddress(), Integer.toBinaryString(info.asInteger(info.getBroadcastAddress()))); System.out.printf("Low Address:\t\t\t%s\t[%s]%n", info.getLowAddress(), Integer.toBinaryString(info.asInteger(info.getLowAddress()))); System.out.printf("High Address:\t\t\t%s\t[%s]%n", info.getHighAddress(), Integer.toBinaryString(info.asInteger(info.getHighAddress()))); System.out.printf("Total usable addresses: \t%d%n", Long.valueOf(info.getAddressCountLong())); System.out.printf("Address List: %s%n%n", Arrays.toString(info.getAllAddresses())); final String prompt = "Enter an IP address (e.g. 192.168.0.10):"; System.out.println(prompt); Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { String address = scanner.nextLine(); System.out.println("The IP address [" + address + "] is " + (info.isInRange(address) ? "" : "not ") + "within the subnet [" + subnet + "]"); System.out.println(prompt); } scanner.close(); }
From source file:examples.SubnetUtilsExample.java
public static void main(String[] args) { String subnet = "192.168.0.1/29"; SubnetUtils utils = new SubnetUtils(subnet); SubnetInfo info = utils.getInfo();//from ww w. j ava 2 s. c o m System.out.printf("Subnet Information for %s:\n", subnet); System.out.println("--------------------------------------"); System.out.printf("IP Address:\t\t\t%s\t[%s]\n", info.getAddress(), Integer.toBinaryString(info.asInteger(info.getAddress()))); System.out.printf("Netmask:\t\t\t%s\t[%s]\n", info.getNetmask(), Integer.toBinaryString(info.asInteger(info.getNetmask()))); System.out.printf("CIDR Representation:\t\t%s\n\n", info.getCidrSignature()); System.out.printf("Supplied IP Address:\t\t%s\n\n", info.getAddress()); System.out.printf("Network Address:\t\t%s\t[%s]\n", info.getNetworkAddress(), Integer.toBinaryString(info.asInteger(info.getNetworkAddress()))); System.out.printf("Broadcast Address:\t\t%s\t[%s]\n", info.getBroadcastAddress(), Integer.toBinaryString(info.asInteger(info.getBroadcastAddress()))); System.out.printf("First Usable Address:\t\t%s\t[%s]\n", info.getLowAddress(), Integer.toBinaryString(info.asInteger(info.getLowAddress()))); System.out.printf("Last Usable Address:\t\t%s\t[%s]\n", info.getHighAddress(), Integer.toBinaryString(info.asInteger(info.getHighAddress()))); System.out.printf("Total usable addresses: \t%d\n", info.getAddressCount()); System.out.printf("Address List: %s\n\n", Arrays.toString(info.getAllAddresses())); final String prompt = "Enter an IP address (e.g. 192.168.0.10):"; System.out.println(prompt); Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { String address = scanner.nextLine(); System.out.println("The IP address [" + address + "] is " + (info.isInRange(address) ? "" : "not ") + "within the subnet [" + subnet + "]"); System.out.println(prompt); } }
From source file:examples.cidr.SubnetUtilsExample.java
public static void main(String[] args) { String subnet = "192.168.0.3/31"; SubnetUtils utils = new SubnetUtils(subnet); SubnetInfo info = utils.getInfo();/*from ww w . j a v a 2 s . c om*/ System.out.printf("Subnet Information for %s:\n", subnet); System.out.println("--------------------------------------"); System.out.printf("IP Address:\t\t\t%s\t[%s]\n", info.getAddress(), Integer.toBinaryString(info.asInteger(info.getAddress()))); System.out.printf("Netmask:\t\t\t%s\t[%s]\n", info.getNetmask(), Integer.toBinaryString(info.asInteger(info.getNetmask()))); System.out.printf("CIDR Representation:\t\t%s\n\n", info.getCidrSignature()); System.out.printf("Supplied IP Address:\t\t%s\n\n", info.getAddress()); System.out.printf("Network Address:\t\t%s\t[%s]\n", info.getNetworkAddress(), Integer.toBinaryString(info.asInteger(info.getNetworkAddress()))); System.out.printf("Broadcast Address:\t\t%s\t[%s]\n", info.getBroadcastAddress(), Integer.toBinaryString(info.asInteger(info.getBroadcastAddress()))); System.out.printf("Low Address:\t\t\t%s\t[%s]\n", info.getLowAddress(), Integer.toBinaryString(info.asInteger(info.getLowAddress()))); System.out.printf("High Address:\t\t\t%s\t[%s]\n", info.getHighAddress(), Integer.toBinaryString(info.asInteger(info.getHighAddress()))); System.out.printf("Total usable addresses: \t%d\n", Integer.valueOf(info.getAddressCount())); System.out.printf("Address List: %s\n\n", Arrays.toString(info.getAllAddresses())); final String prompt = "Enter an IP address (e.g. 192.168.0.10):"; System.out.println(prompt); Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { String address = scanner.nextLine(); System.out.println("The IP address [" + address + "] is " + (info.isInRange(address) ? "" : "not ") + "within the subnet [" + subnet + "]"); System.out.println(prompt); } }
From source file:Main.java
public static String convertToBinary(int num) { return Integer.toBinaryString(num); }
From source file:Main.java
public static String byte2BinaryString(byte singleByte) { return Integer.toBinaryString(singleByte & 0xFF); }
From source file:Main.java
public static String decimalismIntToBinary(String integer) { return Integer.toBinaryString(Integer.parseInt(integer)).toString(); }
From source file:Main.java
public static String ageChangeToBinaryString(int i) { String s = Integer.toBinaryString(i); Object obj = s;// w w w .j a v a2 s . c o m if (s.length() < 7) { obj = new StringBuffer(); for (i = 0; i < 7 - s.length(); i++) { ((StringBuffer) (obj)).append("0"); } ((StringBuffer) (obj)).append(s); obj = ((StringBuffer) (obj)).toString(); } return ((String) (obj)); }
From source file:Main.java
public static String byte2bits(byte b) { int z = b;//w w w . ja va 2s .c o m z |= 256; String str = Integer.toBinaryString(z); int len = str.length(); return str.substring(len - 8, len); }
From source file:Main.java
private static String byte2bits(byte ch) { int z = ch;/* w ww . j a v a2s . co m*/ z |= 256; String str = Integer.toBinaryString(z); int len = str.length(); return str.substring(len - 8, len); }