Java BigInteger类| toByteArray()方法与示例

BigInteger类testBit()方法 (BigInteger Class testBit() method)

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

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

  • testBit() method is used to convert this BigInteger to a byte [] that holds 2's complement denotation of this BigInteger and the array capacity is enough to represent this BigInteger with one extra bit for the sign.

    testBit()方法用于将该BigInteger转换为一个字节[],该字节持有此BigInteger的2的补码表示,并且数组容量足以用一个额外的符号表示此BigInteger。

  • testBit() 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.

    testBit()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • testBit() method does not throw an exception at the time of converting this object to a byte array.

    在将此对象转换为字节数组时, testBit()方法不会引发异常。

Syntax:

句法:

    public byte[] toByteArray();

Parameter(s):

参数:

  • None

    没有

Return value:

返回值:

The return type of this method is byte[], it represents this BigInteger in terms of 2’s complement in byte array.

此方法的返回类型为byte [] ,它以字节数组中2的补码形式表示此BigInteger。

Example:

例:

// Java program to demonstrate the example 
// of byte[] toByteArray() method of BigInteger
import java.math.*;
import java.util.*;
public class ToByteArrayOfBI {
public static void main(String args[]) {
// Initializes a variable str
String str = "145";
// Initializes a BigInteger object  
BigInteger b_int = new BigInteger(str);
// returns the convert this BigInteger 
// into a byte[] that contains 2's complement of 
// this BigInteger
byte[] b_arr = b_int.toByteArray();
for (int i = 0; i < b_arr.length; ++i)
System.out.println("b_int.toByteArray(): " + b_arr[i] + " ");
}
}

Output

输出量

b_int.toByteArray(): 0 
b_int.toByteArray(): -111 

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542005.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

007_Web to lead

转载于:https://www.cnblogs.com/bandariFang/p/6229491.html

设置header_Nginx的这些安全设置,你都知道吗?

Nginx 是最流行的 Web 服务器&#xff0c;可以只占用 2.5 MB 的内存&#xff0c;却可以轻松处理 1w 的 http 请求。做为网站的入口&#xff0c;Nginx 的安全设置重要性不言而喻。下面带你一起去认识一下这些安全配置吧&#xff01;nginx.conf是 Nginx 最主要的配置文件&#xf…

动态路由协议_动态路由协议的类别

动态路由协议Dynamic routing protocols have been divided into 2 categories i.e Distance vector protocols and Link state protocols. Both of these protocols are being explained in detail in this tutorial. 动态路由协议分为距离矢量协议和链路状态协议两大类 。 本…

docker镜像创建与优化

1 . 创建镜像 有两种方法构建镜像&#xff1a; docker commit &#xff1a;将运行的容器保存成镜像Dockerfile&#xff1a;自动构建 使用docker commit 创建镜像分为三步&#xff1a; 运行容器修改容器将容器保存为镜像 举例&#xff1a; [rootdocker ~]# docker load -i…

ISP运营商实验室测试机架拓扑搭建经验分享

大家好&#xff0c;有些日子没更新干货了&#xff0c;近期难得有假期进行修整&#xff0c;思前顾后还是坐下来聊聊自己长期负责维护和搭建的实验室环境。废话不多说&#xff0c;直接上图。因为图较大&#xff0c;分上下部分进行上传。网络主框架&#xff08;上&#xff09;服务…

关于二手交易用户指南怎么写_让用户拍案叫绝文案怎么写?试试这3个方法

“共鸣”到底是什么&#xff1f; 为什么有些文章会引起共鸣&#xff0c;而有些则没有。现在假设为产品家用手持式美容仪写一份副本。 由于主要重点是“家庭使用”&#xff0c;因此您立即想到了“家庭美容”的口号。 尽管这句话很简单易懂&#xff0c;但谈论起来总是很简单……似…

结构化程序goto语句_C ++ goto语句| 查找输出程序| 套装1

结构化程序goto语句Program 1: 程序1&#xff1a; #include <iostream>#include <math.h>using namespace std;int main(){int num1 1;int num2 0;MY_LABEL:num2 num1 * num1;cout << num2 << " ";num1 num1 pow(2, 0);if (num1 < …

docker仓库搭建、加密、用户认证

1 . 含义及理解&#xff1a; 仓库分为公开仓库&#xff08;Public&#xff09;和私有仓库&#xff08;Private&#xff09;两种形式。最大的公开仓库是 Docker Hub&#xff0c;存放了数量庞大的镜像供用户下载。 国内的公开仓库包括 Docker Pool等&#xff0c;可以提供大陆用户…

Centos7+Nginx+Keepalived实现Apache服务的高可用负载均衡

Centos7NginxKeepalived实现Apache服务的高可用&负载均衡今天是2017年的第一天&#xff0c;昨天也就是2016年的最后一天&#xff0c;我尝试部署了Centos7NginxKeepalived实现WEB服务的高可用负载均衡服务&#xff0c;终于在2017年的第一天前完成了&#xff0c;所以在此分享…

客户端通过网口启动可过去的ip_西安交通大学16年3月课程考试《网络组网技术综合训练》作业考核试题...

西安交通大学16年3月课程考试《网络组网技术综合训练》作业考核试题一、单选题(共 20 道试题&#xff0c;共 40 分。)V 1. 下列不属于服务器内部结构的是()A. CPUB. 电源C. 5类双绞线D. 北桥芯片满分&#xff1a;2 分2. 网络中使用光缆的优点是()A. 便宜B. 容易安装C. 是一个工…

mcq 队列_MCQ | 软件工程基础知识/简介(1)

mcq 队列Q1. Which of the following is a part of the software? Q1。 以下哪个是软件的一部分&#xff1f; Programs 程式 Documentation 文献资料 Operating Procedures 运营流程 All of the above 上述所有的 Answer: d. All of the above 答案&#xff1a; d。 上述所有…

docker设置镜像加速器

设置镜像加速器 一般情况下&#xff0c;直接从官方仓库中直接拉取镜像会比较慢&#xff0c;可以设置镜像加速器&#xff0c;相当于一个反向代理。以阿里云为例 1 . 首先获取自己的加速器地址 www.aliyun.com 登陆自己的账号&#xff08;可以是支付宝账号&#xff09; 首页点…

keytool条目_java keytool 常用命令

最近在做ssl连接active directory&#xff0c; 遇到了不少的ssl的问题。连接ssl时会需要用将证书保存到keystore&#xff0c; 而这个步骤刚好就用到了keytool命令。直接敲keytool会有提示如何用这个命令&#xff0c; 但对于完全不懂的我&#xff0c;还是找了下基本命令&#xf…

用JavaScript中的示例进行fill()函数

fill() is a predefined function in JavaScript, which is used to fill all elements of an array with a static value. fill()是JavaScript中的预定义函数&#xff0c;用于用静态值填充数组的所有元素。 Example: 例&#xff1a; <html><head><title>J…

谈谈重载(overload)覆盖(override)与隐藏

这三个概念都是与OO中的多态有关系的。如果单是区别重载与覆盖这两个概念是比较容易的&#xff0c;但是隐藏这一概念却使问题变得有点复杂了&#xff0c;下面说说它们的区别吧。重载是指不同的函数使用相同的函数名&#xff0c;但是函数的参数个数或类型不同。调用的时候根据函…

搭建Harbor私有仓库

1 首先装好docker&#xff1a; 由于之前已安装过&#xff0c;所以直接开起就行 2 . 安装python2.7以上版本 之前编译安装过7.3的&#xff0c;直接用吧 3 . 安装docker-compose docker容器管理工具&#xff0c;是habor的依赖之一。 curl -L "https://github.com/docker…

mysql日志查询指令_MySQL查询日志总结

MySQL查询日志介绍MySQL的查询日志记录了所有MySQL数据库请求的信息。无论这些请求是否得到了正确的执行。默认文件名为hostname.log。默认情况下MySQL查询日志是关闭的。生产环境&#xff0c;如果开启MySQL查询日志&#xff0c;对性能还是有蛮大的影响的。另外很多时候&#x…

thinkphp5.0助手函数占用服务器资源

db(user) 默认情况下&#xff0c;每次请求都会重新连接数据库&#xff0c;这样会占用服务器资源 方法1.如果不想每次都重连可以这样 db("List",[],false) 方法2.还可以直接改function&#xff0c;及则需要把 function db($name , $config [], $force true){retu…

python 无符号整数_Python中的有符号和无符号整数数组

python 无符号整数An array can be declared by using "array" module in Python. 可以通过在Python中使用“数组”模块来声明数组 。 Syntax to import "array" module: 导入“数组”模块的语法&#xff1a; import array as array_alias_nameHere, imp…

mysql快速批量入库_MySQL-批量入库优化

MySQL批量入库的方式循环一条一条入库批量入库通过程序组合 insert into (字段) tbl vlaues(), vlaues(), vlaues(),...事务入库$autoCommit (isset($this->startTransaction) ? !$this->startTransaction : true);$ids array();if ($autoCommit) {$this->startTra…