Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes
CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes

Java > Core Java Code Examples

Byte to Binary Conversion

Byte to Binary Conversion import java.io.*; /** * BinCat is a simple class for reading bytes and * writting them back out in binary representation. */ public class BinCat { BufferedInputStream brIn; PrintStream psOut; public static int BYTES_PER_LINE = 4; public BinCat() { this(System.in,System.out); } public BinCat(InputStream in, OutputStream out) { brIn = new BufferedInputStream(in); if (out instanceof PrintStream) psOut = (PrintStream)out; else psOut = new PrintStream(out); } public void doit() { int ch, cv, bit, cnt; try { for(cnt = 0, ch = brIn.read(); ch >= 0; ch = brIn.read()) { cv = ((int)ch & 0x00ff); for(bit = 7; bit >= 0; bit--) { if ((cv & (2 << bit)) > 0) psOut.print("1"); else psOut.print("0"); } cnt++; if ((cnt % BYTES_PER_LINE) == 0) psOut.println(""); } } catch (IOException e) { } return; } /** * Test main for BinCat */ public static void main(String args[]) { BinCat kitty; kitty = new BinCat(); kitty.doit(); System.exit(0); } }
Computing Fibonacci numbers
Scaled Image
Destroy a servlet session
Listing all running threads
Writing a Thread-Safe Singleton
Applet that demonstrates a Java2D GeneralPath
Interface List and class LinkedList example
Demonstrating mouse events
CheckBox example
Buffering servlet responses
Servlet error handler
Case Insensitive String