Thursday, June 27, 2013

How to convert text to binary in Java

Convert String to Binary in Java




import java.io.*;

public class TexttoBinary {
  private static final int maxBytes = 3;
  public static void main(String[] args) {
  
  BufferedReader in = 
  new BufferedReader(new InputStreamReader(System.in));
  do {
  try {
  System.out.print("Type the number to parse: ");
  int number = Integer.parseInt(in.readLine());
  int Bit;
  String result = "";
  for (int i = maxBytes*8; i >= 0; i--) {
  Bit = 1 << i;
  if (number >= Bit) {
  result += 1;
  number -= Bit;
  }
  else {
  result += 0;
  }
  }
  System.out.println(result);
  }
  catch (NumberFormatException e) {
  System.exit(0);
  }
  catch (IOException e) {
  e.printStackTrace();
  System.exit(1);
  }
  }
  while (true);
  }
}



-----------------------------------------
How to convert binary to text in Java
java: converting binary to text?
Convert String to Binary 
Thread: Converting a string of binary to data, to save to a ...
Thread: conversion text-binary-text
converting binary to string
Thread: Convert String to Binary equivalent
Java: Convert a binary file to text and back again
Searches related to convert text to binary java
java string to binary conversion
java convert binary to string
java binary decimal conversion
convert binary to text linux
convert binary file to text
convert binary to text sql
convert binary to text c++
converting integer binary java
IT Certification Category (English)640x480

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Top Online Courses From ProgrammingKnowledge

Python Course http://bit.ly/2vsuMaS
Java Coursehttp://bit.ly/2GEfQMf
Bash Coursehttp://bit.ly/2DBVF0C
Linux Coursehttp://bit.ly/2IXuil0
C Course http://bit.ly/2GQCiD1
C++ Coursehttp://bit.ly/2V4oEVJ
PHP Coursehttp://bit.ly/2XP71WH
Android Coursehttp://bit.ly/2UHih5H
C# Coursehttp://bit.ly/2Vr7HEl
JavaFx Coursehttp://bit.ly/2XMvZWA
NodeJs Coursehttp://bit.ly/2GPg7gA
Jenkins Course http://bit.ly/2Wd4l4W
Scala Coursehttp://bit.ly/2PysyA4
Bootstrap Coursehttp://bit.ly/2DFQ2yC
MongoDB Coursehttp://bit.ly/2LaCJfP
QT C++ GUI Coursehttp://bit.ly/2vwqHSZ