Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Plz help! string class question

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic