Interesting Integer.parseInt() problem
- From: Knute Johnson <nospam@xxxxxxxxxxxxxxxxx>
- Date: Mon, 30 Jan 2006 17:34:58 -0800
I'm working on a project where I'm being given a string of 0s and 1s and need to mask them against another string of the same. I thought I would convert my string with Integer.parseInt("111",2) but I ran into a problem. You can't parse out 32 bits to an int if the MSB is 1. It throws a NumberFormatException. You can't parse -2147483648 in either radix 2, 8 or 16. My data is of course LSB first so 1 would be 100000000000000000000000000000000 and I can't parse it. Anyway, I thought it was interesting and wondered if anybody knows why this is so?
Thanks,
knute...
public class test { public static void main(String[] args) { // String str = "1111111111111111111111111111111"; // String str = "7fffffff"; // String str = "17777777777"; int n = Integer.parseInt(str,2); System.out.println(n); } }
--
Knute Johnson email s/nospam/knute/ .
- Follow-Ups:
- Re: Interesting Integer.parseInt() problem
- From: Roedy Green
- Re: Interesting Integer.parseInt() problem
- From: Thomas Hawtin
- Re: Interesting Integer.parseInt() problem
- From: opalpa@xxxxxxxxx opalinski from opalpaweb
- Re: Interesting Integer.parseInt() problem
- Prev by Date: Re: Slightly OT: Version Control Software For Java
- Next by Date: Re: Java socket programming
- Previous by thread: Java socket programming
- Next by thread: Re: Interesting Integer.parseInt() problem
- Index(es):
Relevant Pages
|
Loading