日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java BigInteger类| 带示例的shiftLeft()方法

發(fā)布時間:2023/12/1 java 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java BigInteger类| 带示例的shiftLeft()方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

BigInteger類shiftLeft()方法 (BigInteger Class shiftLeft() method)

  • shiftLeft() method is available in java.math package.

    shiftLeft()方法在java.math包中可用。

  • shiftLeft() method is used to shift the given number of bits towards the left side in this BigInteger.

    shiftLeft()方法用于將給定數(shù)量的位向此BigInteger中的左側(cè)移動。

  • shiftLeft() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    shiftLeft()方法是一種非靜態(tài)方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • shiftLeft() method may throw an exception at the time of shifting bits.

    shiftLeft()方法在移位位時可能會引發(fā)異常。

    ArithmeticException: This exception may throw when the given parameter value holds Integer.MIN_VALUE.

    ArithmeticException :當給定參數(shù)值包含Integer.MIN_VALUE時,可能引發(fā)此異常。

Syntax:

句法:

public BigInteger shiftLeft(int number);

Parameter(s):

參數(shù):

  • int number – represents the value in bits and when it holds negative value it performs right shift instead of left.

    int number –表示以位為單位的值,當它保持負值時,它執(zhí)行右移而不是左移。

Return value:

返回值:

The return type of this method is BigInteger, it returns BigInteger that holds the value [(this BigInteger) << (number)].

此方法的返回類型為BigInteger ,它返回保存值[(this BigInteger)<<(number)]的BigInteger。

Example:

例:

// Java program to demonstrate the example // of BigInteger setBit(int pos) method of BigIntegerimport java.math.*; public class SetBitOfBI {public static void main(String args[]) {// Initialize a variable strString str = "10";// Initialize a BigInteger object BigInteger b_int = new BigInteger(str);// Display b_intSystem.out.println("b_int: " + b_int);// Display Binary representation of str System.out.println("Binary Representation of 10: 1010 ");System.out.println();// Here, this method setBit(int) method is used// to set the bit value from "0" to 1" at the// given indices in this BigInteger// b_int and the binary representation of b_int// is 1010 so the bit "1" is set at the given// indices (0) so the new binary representation// is 1011 i.e. 11BigInteger set_bit = b_int.setBit(0);System.out.println("b_int.setBit(0): " + set_bit);System.out.println("Binary Representation of 11: 1011 ");} }

Output

輸出量

b_int: 10 Binary Representation of 10: 1010 b_int.setBit(0): 11 Binary Representation of 11: 1011

翻譯自: https://www.includehelp.com/java/biginteger-shiftleft-method-with-example.aspx

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的Java BigInteger类| 带示例的shiftLeft()方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。