User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 397,719 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,573 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting

Trying to create a method to convert string letters into a two dimensional array

Join Date: Oct 2004
Posts: 15
Reputation: Dounia is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Dounia Dounia is offline Offline
Newbie Poster

Solution Re: Trying to create a method to convert string letters into a two dimensional array

  #2  
Dec 1st, 2004
Hi,

I know the ASCII code for the letter H is: 1001000
You can get the decimal number of H and then try to convert to binary. Here is a small program to do the conversion. You can figureout how to place this into a dimensinal array.
import java.util.*;

class ConvertString
{
public static void main (String [] args)
{
char c = 'H';
int a = c - 0;
int b = 0; intializing b to zero
Stack s = new Stack(); // declaring a new stack

System.out.println(c +" equal in decimal to: " +a);

do
{
b = (a%2); //getting the remainder
s.push(String.valueOf(b)); // push the value of b into the stack
a /= 2; // remove right most digit
} while(a != 0); //continue until all digits computed

while(!s.empty())

System.out.println(s.pop()); //result of H in binary.
}
}

Hope this helped little and good luck.
Dounia
Reply With Quote  
All times are GMT -4. The time now is 2:10 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC