## 2013年9月24日 星期二

### [ Java 文章收集 ] BigInteger 的使用

Preface:

BigInteter 的使用介紹:

BigInteger 的所有操作中，都以二進制補碼形式表示 BigInteger（如 Java 的基本整數型別）。BigInteger 提供所有 Java 的基本整數操作符的對應物，並提供 java.lang.Math 的所有相關方法。另外，BigInteger 還提供以下運算：模算術、GCD 計算、質數測試、素數產生、位操作以及一些其他操作

- BigInteger(String val) : Translates the decimal String representation of a BigInteger into a BigInteger.
- BigInteger(String val, int radix) : Translates the String representation of a BigInteger in the specified radix into a BigInteger.

1. String bigIntStr = "16263054952801281548";
2. BigInteger a = new BigInteger(bigIntStr);
3. System.out.printf("%s > %d\n", a, Long.MAX_VALUE);
4. System.out.printf("'%s' binary = %s\n", a, a.toString(2));

16263054952801281548 > 9223372036854775807
'16263054952801281548' binary = 1110000110110001111110100101000001110000011000001010011000001100

1. BigInteger btwo = new BigInteger("2");
3. System.out.printf("%s-1=%s\n", a, a.subtract(BigInteger.ONE));
4. System.out.printf("%s*2=%s\n", a, a.multiply(btwo));
5. System.out.printf("%s/2=%s\n", a, a.divide(btwo));

16263054952801281548+1=16263054952801281549
16263054952801281548-1=16263054952801281547
16263054952801281548*2=32526109905602563096
16263054952801281548/2=8131527476400640774

1. System.out.printf("2^100=%s\n", btwo.pow(100));

2^100=1267650600228229401496703205376

Supplement:
Java Tutorial > Primitive Data Types
Blog> java处理大整数

### [ FP In Python ] Ch4. Higher-Order Functions

Preface   In the  last chapter  we saw an iterator algebra that builds on the  itertools  module. In some ways,  higher-order functions  (...