根据课本上的算法写的哈
package com.fpf.binarydecimal;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
/**
* 进制转换
*
* @author fengpf
* @version 1.0
* @date 2021/5/20 10:41
*/
@Slf4j
public class BinaryDecimalDemo {
public static void main(String[] args) {
test01(2147483647.2147483647, 2);
test01(2147483647.2147483647, 8);
test01(2147483647.2147483647, 16);
}
/**
* 十进制转二进制
*
* @param num 转换的数字
* @param digint 位数
* @author fengpf
* @date 2021/5/20 12:04
*/
@Test
public static String test01(double num, int digint) {
double dec = num;
int decPre = (int) dec;//整数部分
double decPos = dec - decPre;//小数部分
int decPreTmp = decPre