google-apps-script - 谷歌脚本转换为十六进制
问题描述
使用 Google 表格,我想将值作为十六进制数字存储在单元格中。
但是 usingUtilities.formatString("0x%2x", byte)
将文字“0x%2x”存储在单元格中。
按预期使用Utilities.formatString("0x%2i", byte)
商店“0x [数字]”。
知道我做错了什么吗?
最好的问候斯特凡
解决方案
这是一个可以做你想做的功能:
// function to convert decimal to hexadecimal
function DecToHex(value) {
var result = "";
while( value != 0 ) {
var temp = value % 16;
Logger.log(temp);
var hex = temp < 10 ? String.fromCharCode(temp+48) : String.fromCharCode(temp+55);
result = hex.concat(result);
value = Math.floor(value/16);
}
if( ( result.length %2 ) != 0 ) result = "0"+result;
result = "0x"+result;
return result;
}
推荐阅读
- python - 生成后自动打开
- chocolatey - 使用 Chocolatey 时隐藏安装参数中的键的选项?
- stm32 - 使用 CubeMX 时,PlatformIO 中为 STM32 定义 NVIC 的文件在哪里?
- python - 如果是字典,等号 ('=') 是否传递副本或引用?
- python - 使用 tsv 文件中的列 - python 3
- c# - 使用子记录列表保存记录时出现 EntityFramework 错误
- c++ - 在 3D 渲染场景上绘制 2D HUD 元素
- apache-flink - FlinkSQL - 选择最后一个
- php - 来自 PHP 回显的 Jquery Ajax 成功数据不起作用
- vert.x - vertx 与 mysql 的 tps 性能低