Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Common functions and usage of BigInteger in Java

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "the common functions and usage of BigInteger in Java". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the common functions and usage of BigInteger in Java.

1. Introduction of BigInteger

If an integer data exceeds the maximum type length long of an integer at the time of operation, the data cannot be loaded, so use the BigInteger class to operate at this time. These large numbers are passed in the form of a string.

BigInteger can indeed be described as big compared to Integer. It is used for scientific calculation, Integer can only hold one int, so the maximum value is 31 visits of 2 minus 1, and the decimal system is 2147483647. However, if we need to calculate a larger number, 31 bits are obviously not enough, then BigInteger can meet our needs at this time.

The number of bits that the BigInteger can hold is large. I tried it briefly, and there is no problem with thousands of bits. In addition to the large capacity, BigInteger also encapsulates some common operations, such as the basic operation of ±* /, as well as the operation of absolute value, opposite number, maximum common divisor, prime number, and so on.

2. Common functions of BigInteger

BigInteger (String value): construction method

BigInteger add (BigInteger value): addition

BigInteger subtract (BigInteger value): subtraction

BigInteger multiply (BigInteger value): multiplication

BigInteger divide (BigInteger divisor): division

BigInteger modInverse (BigInteger m): finding the module

BigInteger pow (int exponent): multiplier

BigInteger max (BigInteger value): maximum number

BigInteger min (BigInteger value): minimum

BigInteger abs (): absolute value

BigInteger negate (): inverse number

Int intValue (): converts int and converts BigInteger type data to int.

BigInteger valueOf (long val): convert to BigInteger, convert long type to BigIntege type

Sample code

[title]

Enter an integer n 1

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report