Android 10进制与16进制转换补位

        你永远不知道客户的想法有多奇葩、

         10进制  转换  16进制

          byte[] test = new byte[4];

          test[0]  = (byte)0x36;//写死的数据,放上去多少就是多少,不会改变

          test[1]  = (byte)36;   //系统自动转为16进制    即 24

          test[2]  = (byte) Integer.parseInt("36").getBytes();    //同上

          test[3]  = (byte)intTointByte(36)';             //  也是会被强制转成byte只不过是提前补了  10位转16位的数 ,即

                                                                             intTointByte(36) = 3*16+6 = 54

 

最后的结果:test[0] = 24

test[1] = 24

test[2] = 24

test[3] = 36

 

代码效果即是:  int  36   = byte  36

 

public static int intTointByte(int args)
{
    int hex_all = 0;
    if (args>10){
        int ten_num = Integer.parseInt((args+"").substring(0,1));
        int hex_1 = ten_num*16;
        int hex_2 = Integer.parseInt((args+"").substring(1,2));
        hex_all = hex_1+hex_2;
    }else {
        hex_all = args;
    }
    Log.e("hex_all",hex_all+"");
    return hex_all;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

直到世界尽头szk

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

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

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

打赏作者

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

抵扣说明:

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

余额充值