Help coderanch get a
new server
by contributing to the fundraiser
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:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# NumberFormatException

Ranch Hand
Posts: 61
• Number of slices to send:
Optional 'thank-you' note:
i do no know why intstream fails to parse this string, any help . please.

it returnNumberFormatException

Greenhorn
Posts: 3
• 2
• Number of slices to send:
Optional 'thank-you' note:
you were trying to get a number very very bigger than int type maximum capabilitie.
I dont know if im mistake, but i guess the maximum positive value for a int type is around 2 billion approximately.

Bartender
Posts: 242
27
• 1
• Number of slices to send:
Optional 'thank-you' note:
If you want a much bigger possible number, declare it long instead of int.

Marshal
Posts: 79531
379
• 1
• Number of slices to send:
Optional 'thank-you' note:
Diego Nobrega, welcome to the Ranch
You are correct; you can see the limits for the primitive integer types here. What OP didn't tell us is whether this is an exercise in interconversion between different number bases. If you convert an int to a String representing its binary digits, you will end up with a String much longer than the decimal representation. So 4095₁₀ turns into 11111111111₂. Your four digits have become eleven digits. When you pass that to Integer#parseInt, that method is programmed to interpret that in decimal, so you get the Exception. You can use a similar method which takes the radix as an argument; with a radix of 2, “11111111111” is a valid argument to that method. If you are trying to count the 1 bits in that String, the parseInt method isn't what you want at all; something like this would work better.
There are ready‑made methods in the Integer class which look for 1 and 0 bits, but I don't think there is one to count consecutive runs of bits.

 Think of how stupid the average person is. And how half of them are stupider than that. But who reads this tiny ad? We need your help - Coderanch server fundraiser https://coderanch.com/t/782867/Coderanch-server-fundraiser