简体   繁体   English

javascript将十六进制值的字符串表示形式转换为十六进制

[英]javascript Convert string representation of hex value to hex

In Javascript, how do I convert a string representation of a hex value into it's hex representation ?在 Javascript 中,如何将十六进制值的字符串表示形式转换为它的十六进制表示形式?

What I have returning from a checksum routine is a string value "FE".我从校验和例程返回的是一个字符串值“FE”。 What I need is it's hex representation "\\xFE"我需要的是它的十六进制表示 "\\xFE"

I cannot simply do this, as it gives me an error:我不能简单地这样做,因为它给了我一个错误:

var crc = "FE";
var hex = "\x" + crc;

This just gives me a new 4 character ASCII string:这只是给了我一个新的 4 个字符的 ASCII 字符串:

var crc = "FE";
var hex = "0x" + "FE";

thxs for any guidance.谢谢任何指导。

像这样

var hex = parseInt("FF", 16);

For the string \\xFE , escape the backslash: var hex = '\\\\x'+'FE'对于字符串\\xFE ,转义反斜杠: var hex = '\\\\x'+'FE'

To convert 'FE' to a Number use +('0xFE')要将'FE'转换为数字,请使用+('0xFE')

To show +('0xFE') as a hexadecimal, use (224).toString(16) , or '0x'+((254).toString(16))要将+('0xFE')为十六进制,请使用(224).toString(16)'0x'+((254).toString(16))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将字符串十六进制表示形式转换为字节? - javascript - How do I convert string hex representation to byte ? - javascript 将具有IEEE-754双精度十六进制表示的字符串转换为JavaScript数字变量 - Convert a string with a hex representation of an IEEE-754 double into JavaScript numeric variable 在 JavaScript 中将带有哈希的十六进制字符串转换为带有 0x 的十六进制值的最佳方法? - Best way to convert hex string with hash to hex value with 0x in JavaScript? 如何在Javascript中将十六进制字符串转换为字节,将字节转换为十六进制字符串? - How to convert a hex string to a byte and a byte to a hex string in Javascript? Javascript:将(十六进制)有符号整数转换为 javascript 值 - Javascript: convert a (hex) signed integer to a javascript value 将此十六进制字符串转换为javascript中的整数数组 - Convert this hex string into array of integer in javascript 将大 Integer 转换为 Javascript 中的十六进制字符串 - Convert A Large Integer To a Hex String In Javascript 如何将值转换为十六进制以在 javascript 中以数组形式发送 - how to convert value to hex to send in an array in javascript 在javascript中将ascii转换为十六进制 - Convert ascii to hex in javascript 在 Javascript 中将不透明度转换为十六进制 - Convert opacity to hex in Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM