获取码值和进制转换系统(包括正负数小数)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取码值和进制转换系统(包括正负数小数)相关的知识,希望对你有一定的参考价值。

获取码值和进制转换


  • 程序由来

       本人发现计算机中的计算器木有将十进制小数转二进制的功能,后来发现一些网站将十进制负数转二进制只是求出整数的二进制,然后前面加“-”,这种表示不是真正的负数二进制。于是爱较真儿的我写了一个可以转十进制小数、负数、负数加小数为二进制的系统,供大家学习参考。介于理解代码,代码中运用到了纯拼音。虽然是拼音,但符合代码编写格式。介于个人知识有限,代码如有需要修改和改进的地方,敬请大家评教指正,共同学习。


  • 实现功能:

  1. 获取字符的码值,包括中文。

  2. 进制转换包括:十进制(整数/小数/负数)转成二进制、八进制、十六进制。

  3. 供需要学习Java基础的朋友参考学习。


  • 代码:

  1.   代码语言:Java

  2.   包:

             技术分享图片

  3. 源码:


  • 主方法(main)类:主要是表现用户功能选择界面

package com.main.lt;

import java.util.Scanner;

import com.jinzhizhuanhuan.lt.JinZhiZhuanHuan;
import com.mazhi.lt.HuoQuMaZhi;
import com.menus.lt.Menus;

/**
 * 
 * @author LiuTong
 * @version V1.1
 * 
 * 
 */

public class MainApp {
    public static void main(String[] args) {//主方法
        //创建菜单类对象
        Menus menus = new Menus();
        //创建获取码值方法对象
        HuoQuMaZhi hQMZ = new HuoQuMaZhi();
        //创建进制转换对象
        JinZhiZhuanHuan jinZhiZhuanHuan = new JinZhiZhuanHuan();
        //创建键盘录入对象
        Scanner sc = new Scanner(System.in);
        //使用while循环
        //定义断点,用于退出while循环
        boolean zhuBL = true;
        while(zhuBL){
            //使用菜单对象调用主菜单
            menus.mainMenus();
            //键盘录入,使用switch语句判断,做相应操作(case)
            switch(sc.nextLine()){
            case "1"://获取码值
                hQMZ.huoQuMaZhi();//使用获取码值对象调用获取码值方法
                break;
            case "2"://进制转换
                jinZhiZhuanHuan.jinZhiZhuanHuan();//使用进制转换对象调用进制转换方法
                break;
            case "3":
                zhuBL = false;//断点
                break;
            case "":
                menus.shiKongMenu();//为空菜单
                break;
                default:
                    menus.shuRuCuoWuMenu();//输入错误菜单
                    break;
            }
        }
    }
}

  • 菜单类:

package com.menus.lt;
/**
 * 
 * @author LiuTong
 * @version V1.1
 *
 */
public class Menus {
    //空构造
    public Menus(){
        
    }
    
    //成员方法
    //主菜单
    public void mainMenus(){
        System.out.println("-------------------------主菜单---------------------------");
        System.out.println("1、查询码值\t2、进制转换\t3、退出");
        System.out.print("请输入您的操作:");
    }
    //------------------------------------------字节码------------------------------------
    //字节码菜单
    public void huoQuMaZhiMenus(){
        System.out.println("-------------------------字节码-------------------------");
        System.out.print("请输入内容(中文、英语、符号):");
    }
    
    //------------------------------------------进制转换------------------------------------
    public void jinZhiZhuanHuanMenus(){
        System.out.println("-------------------------进制转换-------------------------");
        System.out.println("1、二进制转成其他进制\t2、八进制转成其他进制\t3、十进制转成其他进制\t4、十六进制转成其他进制\n5、返回");
        System.out.print("请输入您的操作:");
    }
    
    //------------------------------------------十进制转其他进制------------------------------------
    public void shiZhuanQiTaMenus(){
        System.out.println("------------------十进制转其他进制------------------");
        System.out.println("1、转成二进制\t2、转成八进制\t3、转成十六进制\n4、返回");
        System.out.print("请输入您的操作:");
    }
    public void shiZhuanErMenu(){
        System.out.println("------------------十进制转成二进制------------------");
        System.out.print("请输入数据(整数(正负)、小数):");
    }
    public void shiZhuanBaMenu(){
        System.out.println("------------------十进制转成八进制------------------");
        System.out.print("请输入数据(整数(正负)、小数):");
    }
    public void shiZhuanShiLiuMenu(){
        System.out.println("------------------十进制转成十六进制------------------");
        System.out.print("请输入数据(整数(正负)、小数):");
    }
    //-----------------------------------------------------------------------------------------
    //------------------------------------------二进制转其他进制------------------------------------
    public void erZhaunQiTaMenus(){
        System.out.println("------------------二进制转其他进制------------------");
        System.out.println("1、转成八进制\t2、转成十进制\t3、转成十六进制\n4、返回");
        System.out.print("请输入您的操作:");
    }
    public void erZhuanBaMenu(){
        System.out.println("------------------二进制转成八进制------------------");
        System.out.print("请输入数据(1/0):");
    }
    public void erZhuanShiMenu(){
        System.out.println("------------------二进制转成十进制------------------");
        System.out.print("请输入数据(1/0):");
    }
    public void erZhuanShiLiuMenu(){
        System.out.println("------------------二进制转成十六进制------------------");
        System.out.print("请输入数据(1/0):");
    }
    //-----------------------------------------------------------------------------------------
    //------------------------------------------八进制转其他进制------------------------------------
    public void baZhuanQiTaMenus(){
        System.out.println("------------------八进制转其他进制------------------");
        System.out.println("1、转成二进制\t2、转成十进制\t3、转成十六进制\n4、返回");
        System.out.print("请输入您的操作:");
    }
    public void baZhuanErMenu(){
        System.out.println("------------------八进制转成二进制------------------");
        System.out.print("请输入数据(0-7):");
    }
    public void baZhuanShiMenu(){
        System.out.println("------------------八进制转成十进制------------------");
        System.out.print("请输入数据(0-7):");
    }
    public void baZhuanShiLiuMenu(){
        System.out.println("------------------八进制转成十六进制------------------");
        System.out.print("请输入数据(0-7):");
    }
    
    
    //-----------------------------------------------------------------------------------------
    //------------------------------------------十六进制转其他进制------------------------------------
    public void shiLiuZhuanQiTaMenus(){
        System.out.println("------------------十六进制转其他进制------------------");
        System.out.println("1、转成二进制\t2、转成八进制\t3、转成十进制\n4、返回");
        System.out.print("请输入您的操作:");
    }
    public void shiLiuZhuanErMenu(){
        System.out.println("------------------十六进制转成二进制------------------");
        System.out.print("请输入数据:");
    }
    public void shiLiuZhuanBaMenu(){
        System.out.println("------------------十六进制转成十进制------------------");
        System.out.print("请输入数据:");
    }
    public void shiLiuZhuanShiMenu(){
        System.out.println("------------------十六进制转成八进制------------------");
        System.out.print("请输入数据:");
    }
    
    //-----------------------------------------------------------------------------------------

    //输入为空提示菜单
    public void shiKongMenu(){
        System.out.println("输入不能为空,请重新输入!");
    }
    //输入错误提示菜单
    public void shuRuCuoWuMenu(){
        System.out.println("输入错误,请重新输入!");
    }
    //是否继续输入提示
    public void shiFouJiXuMenu(){
        System.out.println("是否继续(Y/N)?");
    }
    
}

  • 获取码值类:

package com.mazhi.lt;

import java.util.Scanner;

import com.jinzhizhuanhuan.lt.JinZhiZhuanHuan;
import com.main.lt.MainApp;
import com.menus.lt.Menus;

/**
 * 
 * @author LiuTong
 * @version V1.1
 *
 */
public class HuoQuMaZhi {
    //空构造
    public HuoQuMaZhi(){}
    //创建菜单对象
    Menus menus = new Menus();
    //定义用户选择方法
    public void huoQuMaZhi(){
        //boolean huoQuMaZhiBL = true;
        menus.huoQuMaZhiMenus();//使用菜单对象调用码值菜单
        byte[] b = new Scanner(System.in).nextLine().getBytes();
        System.out.println(new String(b)+"的字节码值和二进制表示为:");
        for(int c : b){
           System.out.println("字节码值:"+c+"\t"+"字节码值二进制表示:"+Integer.toBinaryString(c));
        }
        System.out.println("------------------------------------------------------");
        //是否继续
        if(new JinZhiZhuanHuan().sel()){
           huoQuMaZhi();
        }else{
           new MainApp().main(null);
        }
    }
}

  • 进制转换类:

package com.jinzhizhuanhuan.lt;

import java.util.Scanner;

import com.main.lt.MainApp;
import com.menus.lt.Menus;

/**
 * 
 * @author LiuTong
 * @version V1.1
 *
 */

public class JinZhiZhuanHuan {//进制转换菜单
    //空构造
    public JinZhiZhuanHuan(){}
    
    //进制转换选择方法
    public void jinZhiZhuanHuan(){
        //创建菜单对象
        Menus menus = new Menus();
        //定义断点
        boolean jinZZHBL = true;
        //while循环
        while(jinZZHBL){
            //使用菜单对象调用进制转换菜单
            menus.jinZhiZhuanHuanMenus();
            //swtich语句,选择现有的操作
            switch(new Scanner(System.in).nextLine()){
            case "1":
                erZhuanQiTa();
                break;
            case "2":
                baZhuanQiTa();
                break;
            case "3":
                shiZhuanQiTa();
                break;
            case "4":
                shiLiuZhuanQiTa();
                break;
            case "5":
                new MainApp().main(null);
                break;
            case "":
                menus.shiKongMenu();
                break;
                default:
                    menus.shuRuCuoWuMenu();
                    break;
            }
        }
    }
    //----------------------------------------二进制转其他进制-----------------------------------------
    //二进制转其他进制
    public void erZhuanQiTa(){
        Menus menus = new Menus();//创建菜单对象
        //定义断点
        boolean erZhuanQiTaBL = true;
        //while循环
        while(erZhuanQiTaBL){
            menus.erZhaunQiTaMenus();
            switch(new Scanner(System.in).nextLine()){
            case "1":
                erZhuanBa();
                break;
            case "2":
                erZhuanShi();
                break;
            case "3":
                erZhuanShiLiu();
                break;
            case "4":
                jinZhiZhuanHuan();//返回
                break;
            case "":
                menus.shiKongMenu();
                break;
                default:
                    menus.shuRuCuoWuMenu();
                    break;
            }
        }
    }
    //----------------------------------二进制转八进制---------------------------------------------
    public void erZhuanBa(){
        new Menus().erZhuanBaMenu();;
        String sel = new Scanner(System.in).nextLine();
        String shi = "";
        if(shiErJinZhi(sel)){
            System.out.println("八进制:"+Integer.toOctalString(Integer.valueOf(Integer.valueOf(sel,2).toString())));
            //判断是否继续
            if(sel()){
                erZhuanBa();
            }else{
                erZhuanQiTa();
            }
        }else{
            System.out.println("输入有误,请重新输入!");
            erZhuanBa();
        }
        
    }
    //----------------------------------二进制转十进制------------------------------------------------
    public void erZhuanShi(){
        new Menus().erZhuanShiMenu();
        String sel = new Scanner(System.in).nextLine();
        if(shiErJinZhi(sel)){
            System.out.println("十进制:"+Integer.valueOf(sel,2).toString());
            //判断是否继续
            if(sel()){
                erZhuanShi();
            }else{
                erZhuanQiTa();
            }
        }else{
            System.out.println("输入有误,请重新输入!");
            erZhuanShi();
        }
    }
    //----------------------------------二进制转十六进制------------------------------------------------
    public void erZhuanShiLiu(){
        new Menus().erZhuanShiLiuMenu();
        String sel = new Scanner(System.in).nextLine();
        if(shiErJinZhi(sel)){
            System.out.println("十六进制:"+Integer.toHexString(Integer.valueOf(Integer.valueOf(sel,2).toString())));
            //判断是否继续
            if(sel()){
                erZhuanShiLiu();
            }else{
                erZhuanQiTa();
            }
        }else{
            System.out.println("输入有误,请重新输入!");
            erZhuanShiLiu();
        }
    }
    
    //-------------------------------------------------------------------------------------------
    //----------------------------------------------八进制转其他进制-----------------------------------
    public void baZhuanQiTa(){
        Menus menus = new Menus();//创建菜单对象
        //定义断点
        boolean baZhuanQiTaBL = true;
        //while循环
        while(baZhuanQiTaBL){
            menus.baZhuanQiTaMenus();
            switch(new Scanner(System.in).nextLine()){
            case "1":
                baZhuanEr();
                break;
            case "2":
                baZhuanShi();
                break;
            case "3":
                baZhuanShiLiu();
                break;
            case "4":
                jinZhiZhuanHuan();//返回
                break;
            case "":
                menus.shiKongMenu();
                break;
                default:
                    menus.shuRuCuoWuMenu();
                    break;
            }
        }
    }
    //------------------------------------------------八转二---------------------------------------
    public void baZhuanEr(){
        new Menus().baZhuanErMenu();
        String sel = new Scanner(System.in).nextLine();
        if(shiBaJinZhi(sel)){
            System.out.println("二进制:"+Integer.toBinaryString(Integer.valueOf(Integer.valueOf(sel,8).toString())));
            //判断是否继续
            if(sel()){
                baZhuanEr();
            }else{
                baZhuanQiTa();
            }
        }else{
            System.out.println("输入有误,请重新输入!");
            baZhuanEr();
        }
    }
    //------------------------------------------------八转十---------------------------------------
    public void baZhuanShi(){
        new Menus().baZhuanShiMenu();;
        String sel = new Scanner(System.in).nextLine();
        if(shiBaJinZhi(sel)){
            System.out.println("十进制:"+Integer.valueOf(Integer.valueOf(sel,8).toString()));
            //判断是否继续
            if(sel()){
                baZhuanShi();
            }else{
                baZhuanQiTa();
            }
        }else{
            System.out.println("输入有误,请重新输入!");
            baZhuanShi();
        }
    }
    //-------------------------------------------------------------------------------------------

    //------------------------------------------------八转十六---------------------------------------
    public void baZhuanShiLiu(){
        new Menus().baZhuanShiLiuMenu();;
        String sel = new Scanner(System.in).nextLine();
        if(shiBaJinZhi(sel)){
            System.out.println("二进制:"+Integer.toHexString(Integer.valueOf(Integer.valueOf(sel,8).toString())));
            //判断是否继续
            if(sel()){
                baZhuanShiLiu();
            }else{
                baZhuanQiTa();
            }
        }else{
            System.out.println("输入有误,请重新输入!");
            baZhuanShiLiu();
        }
    }
    //-------------------------------------------------------------------------------------------
    //----------------------------------------------十进制转其他进制-----------------------------------
    //十转其他
    public void shiZhuanQiTa(){
        //创建菜单目录
        Menus menus = new Menus();
        //定义断点
        boolean shiZhuanQiTaBL = true;
        while(shiZhuanQiTaBL){
            menus.shiZhuanQiTaMenus();//调用十转其他进制菜单
            //switch语句
            switch(new Scanner(System.in).nextLine()){
            case "1":
                shiZhuanEr();
                break;
            case "2":
                shiZhuanBa();
                break;
            case "3":
                shiZhuanShiLiu();
                break;
            case "4":
                jinZhiZhuanHuan();
                break;
            case "":
                menus.shiKongMenu();
                break;
                default:
                    menus.shuRuCuoWuMenu();
                    break;
            }
        }
    }
    //-------------------------十进制转成二进制---------------------------
    public void shiZhuanEr(){
        //定义断点
        boolean shiZhuanErBL = true;
        while(shiZhuanErBL){
            new Menus().shiZhuanErMenu();
            String str = new Scanner(System.in).nextLine();
            if(shuZi(str)){
                String regex2 = "-?[0-9]+";
                boolean n = str.matches(regex2);
                //整数部分的二进制
                String l1 = "";
                if(n){
                    System.out.println("二进制:"+Integer.toBinaryString(Integer.valueOf(str)));
                    //判断是否继续
                    if(sel()){
                        shiZhuanEr();
                    }else{
                        shiZhuanQiTa();
                    }
                }else if(catc(str)){
                    String [] strs = str.split("\\.");
                    System.out.println("二进制"+Integer.toBinaryString(Integer.valueOf(strs[0])));
                    //判断是否继续
                    if(sel()){
                        shiZhuanEr();
                    }else{
                        shiZhuanQiTa();
                    }
                }else{
                    //分割字符串,得到整数部分和小数部分
                    String [] strs = str.split("\\.");
                    if(strs[1]==""){
                        System.out.println("二进制:"+Integer.toBinaryString(Integer.valueOf(str)));
                    }else if(Integer.valueOf(strs[0])>=1){//判断整数部分是否大于1
                        l1 = Integer.toBinaryString(Integer.valueOf(strs[0]));//得到整数部分二进制
                        
                    }else if(str.startsWith("-")){
                            l1 =Integer.toBinaryString(Integer.valueOf(strs[0]));
                    }else{
                            l1 = "0";
                    }
                    
                    //得到小数部分的二进制
                    String xiao = "0."+strs[1];
                    double xiaoShu = Double.valueOf("0."+strs[1]);
                    //System.out.println(xiaoShu);
                    String l2;//小数部分二进制
                    double b = 0;//每次的乘积
                    int count = xiao.length();
                    StringBuilder sb = new StringBuilder();
                    while(count>=0){
                        b = xiaoShu*2;
                    if(b>=1){
                        sb.append(1);
                        xiaoShu = b-1;
                    }else if(xiaoShu==0){
                        break;
                    }else{
                        sb.append(0);
                        xiaoShu = b;
                    }
                        count--;
                    }
                    //输出二进制
                    System.out.println("二进制:"+l1+"."+sb);
                    //判断是否继续
                    if(sel()){
                        shiZhuanEr();
                    }else{
                        shiZhuanQiTa();
                    }
                }            
            }else{
                shiZhuanEr();
            }
        }
    }
    //-------------------------十进制转成八进制---------------------------
    public void shiZhuanBa(){
        //定义断点
        boolean shiZhuanBaBL = true;
        while(shiZhuanBaBL){
            new Menus().shiZhuanBaMenu();
            String str = new Scanner(System.in).nextLine();
            if(shuZi(str)){
                String regex2 = "-?[0-9]*";
                boolean n = str.matches(regex2);
                //整数部分的八进制
                String l1 = "";
                if(n){
                    System.out.println("八进制:"+Integer.toOctalString(Integer.valueOf(str)));
                    //判断是否继续
                    if(sel()){
                        shiZhuanBa();
                    }else{
                        shiZhuanQiTa();
                    }
                }else if(catc(str)){
                    String [] strs = str.split("\\.");
                    System.out.println("八进制:"+Integer.toOctalString(Integer.valueOf(strs[0])));
                    //判断是否继续
                    if(sel()){
                        shiZhuanBa();
                    }else{
                        shiZhuanQiTa();
                    }
                }else{
                    //分割字符串,得到整数部分和小数部分
                    String [] strs2 = str.split("\\.");
                    if(strs2[1]==""){
                        System.out.println("八进制:"+Integer.toOctalString(Integer.valueOf(str)));
                    }else if(Integer.valueOf(strs2[0])>=1){//判断整数部分是否大于1
                        l1 = Integer.toOctalString(Integer.valueOf(strs2[0]));//得到整数部分八进制
                        
                    }else if(str.startsWith("-")){
                        l1 = Integer.toOctalString(Integer.valueOf(strs2[0]));
                    }else{
                        l1 = "0";
                    }
                    
                    //得到小数部分的八进制
                    String xiao = "0."+strs2[1];
                    double xiaoShu = Double.valueOf("0."+strs2[1]);
                    //System.out.println(xiaoShu);
                    String l2;
                    double b = 0;//每次的乘积
                    int count = xiao.length();
                    StringBuilder sb = new StringBuilder();
                    while(count>=0){
                        b = xiaoShu*8;
                        if((int)b>=1){
                            sb.append((int)b);
                            xiaoShu = b-(int)b;
                        }else if(xiaoShu==0){
                            break;
                        }else{
                            sb.append(0);
                            xiaoShu = b;
                        }
                        count--;
                    }
                    System.out.println("八进制:"+l1+"."+sb);
                    //判断是否继续
                    if(sel()){
                        shiZhuanBa();
                    }else{
                        shiZhuanQiTa();
                    }
                }        
            }else{
                shiZhuanEr();
            }
        }
    }
    //-------------------------十进制转成十六进制---------------------------
    public void shiZhuanShiLiu(){
        //定义断点
        boolean shiZhuanShiLiuBL = true;
        while(shiZhuanShiLiuBL){
            new Menus().shiZhuanShiLiuMenu();
            String str = new Scanner(System.in).nextLine();
            if(shuZi(str)){
                String regex2 = "-?[0-9]+";
                boolean n = str.matches(regex2);
                //整数部分的十六进制
                String l1 = "";
                if(n){
                    System.out.println("十六进制:"+Integer.toHexString(Integer.valueOf(str)));
                    //判断是否继续
                    if(sel()){
                        shiZhuanShiLiu();
                    }else{
                        shiZhuanQiTa();
                    }
                }else if(catc(str)){
                    String [] strs = str.split("\\.");
                    System.out.println("十六进制:"+Integer.toHexString(Integer.valueOf(strs[0])));
                    //判断是否继续
                    if(sel()){
                        shiZhuanShiLiu();
                    }else{
                        shiZhuanQiTa();
                    }
                }else{
                    //分割字符串,得到整数部分和小数部分
                    String [] strs2 = str.split("\\.");
                    if(strs2[1]==""){
                        System.out.println("十六进制:"+Integer.toHexString(Integer.valueOf(str)));
                    }else if(Integer.valueOf(strs2[0])>=1){//判断整数部分是否大于1
                        l1 = Integer.toHexString(Integer.valueOf(strs2[0]));//得到整数部分十六进制
                        
                    }else if(str.startsWith("-")){
                        l1 = Integer.toHexString(Integer.valueOf(strs2[0]));
                    }else{
                        l1 = "0";
                    }
                    //得到小数部分的十六进制
                    String xiao = "0."+strs2[1];
                    double xiaoShu = Double.valueOf("0."+strs2[1]);
                    //System.out.println(xiaoShu);
                    String l2;//小数部分十六进制
                    double b = 0;//每次的乘积
                    int count = xiao.length();
                    StringBuilder sb = new StringBuilder();
                    while(count>=0){
                        b = xiaoShu*16;
                        if((int)b>=1){
                            sb.append((int)b);
                            xiaoShu = b-(int)b;
                        }else if(xiaoShu==0){
                            break;
                        }else{
                            sb.append(0);
                            xiaoShu = b;
                        }
                        count--;
                    }
                    System.out.println("十六进制:"+l1+"."+sb);
                    //判断是否继续
                    if(sel()){
                        shiZhuanShiLiu();
                    }else{
                        shiZhuanQiTa();
                    }
                }
            }else{
                shiZhuanShiLiu();
            }
        }
    }
    //------------------------------十六进制转其他进制--------------------------------
    public void shiLiuZhuanQiTa(){
        Menus menus = new Menus();//创建菜单对象
        //定义断点
        boolean shiLiuZhuanQiTaBL = true;
        //while循环
        while(shiLiuZhuanQiTaBL){
            menus.shiLiuZhuanQiTaMenus();
            switch(new Scanner(System.in).nextLine()){
            case "1":
                shiLiuZhuanEr();
                break;
            case "2":
                shiLiuZhuanBa();
                break;
            case "3":
                shiLiuZhuanShi();
                break;
            case "4":
                jinZhiZhuanHuan();//返回
                break;
            case "":
                menus.shiKongMenu();
                break;
                default:
                    menus.shuRuCuoWuMenu();
                    break;
            }
        }
    }
    //-------------------------十六转二--------------------------
    public void shiLiuZhuanEr(){

        new Menus().shiLiuZhuanErMenu();;
        String sel = new Scanner(System.in).nextLine();
        String shi = "";
        if(shiShiLiuJinZhi(sel)){
            System.out.println("二进制:"+Integer.toBinaryString(Integer.valueOf(Integer.valueOf(sel,16).toString())));
            //判断是否继续
            if(sel()){
                shiLiuZhuanEr();
            }else{
                shiLiuZhuanQiTa();
            }
        }else{
            System.out.println("输入有误,请重新输入!");
            shiLiuZhuanEr();
        }
    }
    //-------------------------十六转八--------------------------
    public void shiLiuZhuanBa(){
        new Menus().shiLiuZhuanBaMenu();
        String sel = new Scanner(System.in).nextLine();
        String shi = "";
        if(shiShiLiuJinZhi(sel)){
            System.out.println("八进制:"+Integer.toOctalString(Integer.valueOf(Integer.valueOf(sel,16).toString())));
            //判断是否继续
            if(sel()){
                shiLiuZhuanBa();
            }else{
                shiLiuZhuanQiTa();
            }
        }else{
            System.out.println("输入有误,请重新输入!");
            shiLiuZhuanBa();
        }
    }
    //-------------------------十六转十--------------------------
    public void shiLiuZhuanShi(){
        new Menus().shiLiuZhuanShiMenu();
        String sel = new Scanner(System.in).nextLine();
        String shi = "";
        if(shiShiLiuJinZhi(sel)){
            System.out.println("十进制:"+Integer.valueOf(Integer.valueOf(sel,16).toString()));
            //判断是否继续
            if(sel()){
                shiLiuZhuanShi();
            }else{
                shiLiuZhuanQiTa();
            }
        }else{
            System.out.println("输入有误,请重新输入!");
            shiLiuZhuanShi();
        }
    }
    //-------------------------输入判断Yes or No---------------------------
    public boolean sel(){
        boolean bl = true;
        new Menus().shiFouJiXuMenu();
        String str = new Scanner(System.in).nextLine();
        if(str.equalsIgnoreCase("Y")){
            return true;
        }else if(str.equalsIgnoreCase("N")){
            return false;
        }else {
            System.out.println("输入有误,请重新输入!");
            bl = sel();
        }
        return bl;
    }
    
    //-------------------------判断是否为数字----------------------------
    //判断是否为数字
    public static boolean shuZi(String str){
        String regex1 = "-?[0-9]+(\\.[0-9]+)?";
        boolean returnBoolean;
        boolean m = str.matches(regex1);
        if(str ==""){
            new Menus().shiKongMenu();
            
            returnBoolean = false;
        }else if(m){
            
            returnBoolean = true;
        }else{
            System.out.println("您的输入含有不是数字的内容!");
            returnBoolean = false;
        }
        return returnBoolean;
    }
    //-------------------------判断.后面的数字是否等于0----------------------------
    //判断.后面的数是否等于0
    public static boolean catc(String str){
        boolean bl = false;
        String [] strs = str.split("\\.");
        if(Integer.valueOf(strs[1])==0){
            bl = true;
        }
        return bl;
    }
    //-----------------------------判断是否是二进制----------------------------------
    //判断是否为二进制
    public static boolean shiErJinZhi(String str){
        boolean er = false;
    /*    char[] ch = str.toCharArray();
        for(char c : ch){
            if(c =='0' || c == '1'){
                er = true;
            }
        }*/
        String regex = "[10]+";
        if(str.matches(regex)){
            er = true;
        }
        return er;
    }
    //-----------------------------判断是否是八进制----------------------------------
    //判断是否为八进制
    public static boolean shiBaJinZhi(String str){
        boolean ba = false;
        char[] ch = str.toCharArray();
        for(char c : ch){
            if(c >= '0' &&  c<= '7'){
                ba = true;
            }
        }
        return ba;
    }
    //----------------------------判断是否是十六进制-----------------------------------
    //判断是否为十六进制
    public static boolean shiShiLiuJinZhi(String str){
        boolean ba = false;
        String str1 = "-?[0-9A-Fa-f]+";
        if(str.matches(str1)){
            ba = true;
        }
        return ba;
    }
}


以上是关于获取码值和进制转换系统(包括正负数小数)的主要内容,如果未能解决你的问题,请参考以下文章

Int32 最大的数值是多少???(附十进制十六进制相互转换且包含正负数的java代码)

将十进制数转换为分数 AS3

正整数提取

正负数的源码 反码 补码 转

将小数转换为只有两位数的二进制:1 和 2

如何将数值转化为二进制数?