集册 Java实例教程 将大整数解析并格式化为二进制,八进制和十六进制

将大整数解析并格式化为二进制,八进制和十六进制

欢马劈雪     最近更新时间:2020-01-02 10:19:05

424
将大整数解析并格式化为二进制,八进制和十六进制

import java.math.BigInteger;


public class Main {
/**
n o w j a   v  a . c o m - 时  代  Java 提供 
**/

  public void m() throws Exception {

    BigInteger bi = new BigInteger("1023");


    // Parse and format to binary

    bi = new BigInteger("111111111111", 2);

    String s = bi.toString(2); 


    // Parse and format to octal

    bi = new BigInteger("1777", 8); 

    s = bi.toString(8); 
    /**
     * nowjava - 时  代  Java 提 供 
    **/


    // Parse and format to decimal

    bi = new BigInteger("1012323"); 

    s = bi.toString(); 


    // Parse and format to hexadecimal

    bi = new BigInteger("3f123f", 16); 

    s = bi.toString(16); 


    
展开阅读全文