This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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
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 188.8.131.52. 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