Results 1 to 2 of 2

Thread: Problem to convert binary to string

  1. #1
    Join Date
    Apr 2011
    Posts
    1

    Problem to convert binary to string

    Hello,i'm new in java.now i'm working with text conversion.i'm done with conversion string to binary but i dont know how to convert the binary back to original string.below is my working code for text to binary.anyone plez help me to solve this.TQ

    HTML Code:
    import java.util.*;
    import java.io.*;
    public class textconversion{
    public static void main(String[] args) {
    
    
    
    	//String choice = "y";
     	//while (choice.equalsIgnoreCase("y")) {       
    
    		Scanner input = new Scanner(System.in);
    
    		System.out.println ("Enter Message: ");
    		String msg = input.nextLine();
    
    
    		System.out.println ("Enter Key: ");
    		String key = input.nextLine();
    		int keylen = key.length();
    	
    
    
    
    		byte[] bytes2 = msg.getBytes();
      		StringBuilder binary2 = new StringBuilder();
      		for (byte b : bytes2) {
         			int val = b;
         			for (int i = 0; i < 8; i++) {
            		binary2.append((val & 128) == 0 ? 0 : 1);
            		val <<= 1;
         		}
         		binary2.append(' ');
      	}
    	System.out.println();
    	System.out.println();
      	//System.out.println("Your Message"+" <" + msg + "> Successfully Converted Into Binary: ");
    	System.out.println();
    	//System.out.println(binary2);
    	
    	if(keylen <= 25){
      		byte[] bytes = key.getBytes();
      		StringBuilder binary = new StringBuilder();
      		for (byte b : bytes) {
         			int val = b;
         			for (int i = 0; i < 8; i++) {
            			binary.append((val & 128) == 0 ? 0 : 1);
            			val <<= 1;
         			}
         			binary.append(' ');
      		}
    		System.out.println();
    		System.out.println();
      		System.out.println("Your Key"+" <" + key + "> Successfully Converted Into Binary: ");
    		System.out.println();
    		System.out.println(binary);
    
    	
    	
    	
    	//}
    
    		}
    			}
    				}

  2. #2
    Join Date
    Dec 2007
    Posts
    2,291

    Re: Problem to convert binary to string

    When you store Binary data into table, it does some encryption and then saves encrypted data to table, convert and Cast definitely won't work in this case, so how come SQL converts encrypted data to string without knowing the key? You have to find someother way to decrypt the binary data and then convert/cast.

Similar Threads

  1. Convert string to binary in java
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 28-01-2010, 01:36 PM
  2. c program to convert decimal to binary
    By Oswaldo in forum Software Development
    Replies: 3
    Last Post: 25-11-2009, 03:45 PM
  3. Convert binary to decimal in java
    By Seraphim in forum Software Development
    Replies: 2
    Last Post: 20-05-2009, 09:19 AM
  4. Convert Integer to a String in Binary Notation
    By Naval in forum Software Development
    Replies: 2
    Last Post: 16-03-2009, 09:12 PM
  5. Convert Hex Value to Date from Binary Reg Key
    By RobT in forum Windows Server Help
    Replies: 4
    Last Post: 01-04-2005, 11:55 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,046,520.12393 seconds with 17 queries