博客
关于我
Android/TextView 16进制显示,加0x头,不足2位补0
阅读量:664 次
发布时间:2019-03-15

本文共 432 字,大约阅读时间需要 1 分钟。

首先,通过ToString方法将进度值转化为16进制字符串表示:var str = Integer.toHexString(progress);然后,将转换后的字符串转换回整数值并获取其字节表示:// 错误的写法:直接将字符串转换为字节可能会导致错误// orderArr[3] = str.toInt(16).toByte();orderArr[3] = Integer.parseInt(str, 16).toByte();最后,根据字符串长度决定显示格式:msg.text = (str.length > 1) ? "0x$str" : "0x0$str";
  • 以上代码片段展示了如何将10进制数转换为16进制字符串,并将其反转化为字节值。
  • 注意:Integer.parseInt方法用于在指定进制下解析字符串。
  • 错误写法:直接使用str.toInt(16)可能会导致与预期值不符的结果。
  • 另外,字符串长度为1时,为了保持格式统一可以在前面补充一个"0x0"。

转载地址:http://hxxmz.baihongyu.com/

你可能感兴趣的文章
OAuth2.0_授权服务配置_资源服务测试_Spring Security OAuth2.0认证授权---springcloud工作笔记146
查看>>
OAuth2.0_环境介绍_授权服务和资源服务_Spring Security OAuth2.0认证授权---springcloud工作笔记138
查看>>
OAuth2.0_环境搭建_Spring Security OAuth2.0认证授权---springcloud工作笔记139
查看>>
oauth2.0协议介绍,核心概念和角色,工作流程,概念和用途
查看>>
OAuth2授权码模式详细流程(一)——站在OAuth2设计者的角度来理解code
查看>>
OAuth2:项目演示-模拟微信授权登录京东
查看>>
OA系统多少钱?OA办公系统中的价格选型
查看>>
OA系统选型:选择好的工作流引擎
查看>>
OA让企业业务流程管理科学有“据”
查看>>
OA项目之我的会议(会议排座&送审)
查看>>
OA项目之我的会议(查询)
查看>>
Object c将一个double值转换为时间格式
查看>>
object detection之Win10配置
查看>>
object detection训练自己数据
查看>>
object detection错误Message type "object_detection.protos.SsdFeatureExtractor" has no field named "bat
查看>>
object detection错误之Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
查看>>
object detection错误之no module named nets
查看>>
Object of type 'ndarray' is not JSON serializable
查看>>
Object Oriented Programming in JavaScript
查看>>
object references an unsaved transient instance - save the transient instance before flushing
查看>>