Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #7631

Re: BitSet vs BigInteger (false Android doc)

Date 2011-09-06 10:33 -0700
From Patricia Shanahan <pats@acm.org>
Newsgroups comp.lang.java.programmer
Subject Re: BitSet vs BigInteger (false Android doc)
References (5 earlier) <j3tqr7$vp8$1@news.albasani.net> <_ZGdna1ucfWYH__TnZ2dnUVZ_oudnZ2d@earthlink.com> <j3u3me$k4s$1@news.albasani.net> <4e655c24$0$308$14726298@news.sunsite.dk> <j44ga5$970$1@news.albasani.net>
Message-ID <pbmdnZtHEfnnxPvTnZ2dnUVZ_uWdnZ2d@earthlink.com> (permalink)

Show all headers | View raw


On 9/5/2011 11:58 PM, Jan Burse wrote:
...
> - BigInteger is also not dependent for positive values on some
> two's complement, sign-plus-maginitude or one's complement etc..,
> since these presentation were invented for negative values.
...

In dealing with the bit operations BigInteger does have to deal with the
issues of 2's complement. The API supports bit operations on negative,
as well as positive, BigInteger values, and requires 2's complement
behavior. For example, this program prints "-4":

import java.math.BigInteger;
public class BigIntegerTest {
   public static void main(String[] args) {
     BigInteger x = BigInteger.valueOf(-3);
     BigInteger y = BigInteger.valueOf(-2);
     System.out.println(x.and(y));
   }
}

This program prints "-1", despite the positive inputs to the bit
manipulation.

import java.math.BigInteger;
public class BigIntegerTest {
   public static void main(String[] args) {
     BigInteger x = BigInteger.valueOf(3);
     BigInteger y = BigInteger.valueOf(2);
     System.out.println(x.or(y.not()));
   }
}

I suppose, if they felt that the never-negative subset of the
BigInteger bit manipulations were particularly useful and important, the
developers could have done some special case optimization to avoid the
conversions. The combination of the comment in question and reading the
code shows that they did not take that path. Instead, they always
convert for bit manipulation and advise use of BitSet instead.

Patricia

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-02 21:48 +0200
  Re: BitSet vs BigInteger (false Android doc) Arne Vajhøj <arne@vajhoej.dk> - 2011-09-02 16:23 -0400
    Re: BitSet vs BigInteger (false Android doc) Patricia Shanahan <pats@acm.org> - 2011-09-02 13:34 -0700
      Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-02 22:51 +0200
        Re: BitSet vs BigInteger (false Android doc) Patricia Shanahan <pats@acm.org> - 2011-09-02 18:58 -0700
          Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-03 20:15 +0200
            Re: BitSet vs BigInteger (false Android doc) Patricia Shanahan <pats@acm.org> - 2011-09-03 12:37 -0700
              Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-03 22:46 +0200
                Re: BitSet vs BigInteger (false Android doc) Patricia Shanahan <pats@acm.org> - 2011-09-03 16:32 -0700
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-04 02:58 +0200
                Re: BitSet vs BigInteger (false Android doc) Arne Vajhøj <arne@vajhoej.dk> - 2011-09-05 19:32 -0400
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-06 08:58 +0200
                Re: BitSet vs BigInteger (false Android doc) Lew <lewbloch@gmail.com> - 2011-09-06 00:41 -0700
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-06 11:57 +0200
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-06 12:12 +0200
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-06 12:44 +0200
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-06 12:02 +0200
                Re: BitSet vs BigInteger (false Android doc) Patricia Shanahan <pats@acm.org> - 2011-09-06 13:38 -0700
                Re: BitSet vs BigInteger (false Android doc) Patricia Shanahan <pats@acm.org> - 2011-09-06 10:33 -0700
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-06 22:28 +0200
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-06 22:41 +0200
                Re: BitSet vs BigInteger (false Android doc) Patricia Shanahan <pats@acm.org> - 2011-09-06 14:34 -0700
                Re: BitSet vs BigInteger (false Android doc) Lew <lewbloch@gmail.com> - 2011-09-06 14:51 -0700
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-07 00:33 +0200
                Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-07 00:40 +0200
            Re: BitSet vs BigInteger (false Android doc) Arne Vajhøj <arne@vajhoej.dk> - 2011-09-05 19:26 -0400
      Re: BitSet vs BigInteger (false Android doc) Robert Klemme <shortcutter@googlemail.com> - 2011-09-03 17:01 +0200
    Re: BitSet vs BigInteger (false Android doc) Jan Burse <janburse@fastmail.fm> - 2011-09-02 22:49 +0200
      Re: BitSet vs BigInteger (false Android doc) Gene Wirchenko <genew@ocis.net> - 2011-09-02 14:48 -0700
  Re: BitSet vs BigInteger (false Android doc) Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-09-03 13:54 -0400

csiph-web