File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Plz help!     string class question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Plz help!     string class question" Watch "Plz help!     string class question" New topic
Author

Plz help! string class question

zoster gibrilian
Greenhorn

Joined: Sep 17, 2003
Posts: 7
Hi,
I have to define by "hard coding!?" a 32-bit binary string that represents an IP address.
1)Can u help me with a command to do this?
2)What is the bit-length of the testNum string below?
string testNum = "10000010111101010001101100000010";
3)What is hard coding?
Thanks
Ouaknin lionel
Greenhorn

Joined: Sep 12, 2003
Posts: 14
I can't say I fully understood your question....
- Hard coding means putting a litteral value in the code instead of getting this value through user input or file.
- an IP address is made of 4 bytes. a byte = 8 bit. A byte in java has the type

a byte can take a value from -127 to 127.
An integer is also encoded in 4 for bytes. You can put an IP address into an integer or an array of 4 bytes.
for the array it is simple:

for an integer use hex values.here i'm a bit lost...


"Nobody will ever need more than 256 kb of ram" -Bill Gates
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Terms like "binary string" are always a bit ambiguous. You did show a correct string representation of 32 1s and 0s which sounds like what was asked for. Are you comfortable converting integer to binary and back?
IP addresses are usually given as 4 numbers, each between 0 and 255, like 11.96.8.175. You can make each number an 8 bit binary and get your 32 bit string.
IP doesn't always interpret the address as 8-bit chunks. I forgot the particulars as soon as my networking class was over, but it can use 6-bit chunks or 10 bits or whatever the addressing scheme of the day requires. Going that deep into addressing is about the only reason I can think of to worry about binary representations. Which means, I'm curious about what you're up to!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Plz help! string class question