•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 430,118 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 3,335 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
Views: 5717 | Replies: 2
![]() |
| |
•
•
Join Date: Nov 2004
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I'm currently stuck in my program.
I'm supposed to create a new method that inputs a message string and takes each letter and converts it into a two dimensional array of 1's and 0's. For example the letter 'H' would be
10001
10001
11111
10001
10001
My thoughts were to create a for loop and use the .charAt() method to isolate each char in the string. But from there I'm not quite sure where to go to take that char and convert it into the two dimensional array. Any suggestions?
I'm supposed to create a new method that inputs a message string and takes each letter and converts it into a two dimensional array of 1's and 0's. For example the letter 'H' would be
10001
10001
11111
10001
10001
My thoughts were to create a for loop and use the .charAt() method to isolate each char in the string. But from there I'm not quite sure where to go to take that char and convert it into the two dimensional array. Any suggestions?
•
•
Join Date: Oct 2004
Posts: 15
Reputation:
Rep Power: 4
Solved Threads: 0
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
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
•
•
Join Date: Nov 2004
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Re: Trying to create a method to convert string letters into a two dimensional array
#3
Dec 6th, 2004
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Edit1->Text (Iterate over text -Rather Urgent (C++)
- Validation with js of two dimensional array (JavaScript / DHTML / AJAX)
- 2 dimensional array class (C)
- Reading in certain columns from CSV files into array C++ (C++)
- How to transpose a matrix? (Java)
- Help with Java programming for lottery (Java)
- Need Help With two-dimensional array (VB.NET)
Other Threads in the Java Forum
- Previous Thread: Java Applets
- Next Thread: Background Colors


Hybrid Mode