十六进制转二进制

思路分析

String[] str1= {"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"};
例如十六进制2B:
因为'0'<='2'<='9',所以x='2'-'0'=2
所以str1[x]="0010",即十六进制2所对应的二进制
因为'A'<='B'<='F',所以x='B'-'A'+10=11
所以str1[x]="1011",即十六进制B所对应的二进制
综上:十六进制2B所对应的二进制数为0010 1011

代码如下

private static String[] Convert16To2(String str16) {
    String[] str1= {"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"};
    String[] str2=new String[str16.length()];
    int x;
    for(int i=0;i<str16.length();i++) {
        char c=str16.charAt(i);
        if(c<'0'||c>'9') {
            x=c-'A'+10;
        }else {
            x=c-'0';
        }
        str2[i]=str1[x];
    }
    return str2;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小码boy!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值