javascript Perl 包
javascript Perl pack
首先,我告诉你
我不会说英语,但我想尝试获取有关如何将 Perl 包实施到 Javascript 中以制作 node.js 模块的信息。
为此,我想获得有关 Perl 包的更多信息。特别是我特别想知道的资料"C,H*,N"。
此外,如果我能获得有关 jspack 的更多信息,那就太好了。
提前致谢。
我实际尝试过的。
然而,它没有用。
pack 'C'
、pack 'N'
和 pack 'H*'
用于创建字节序列。
my $bytes = pack('C', $uint8);
# Array of bytes
var bytes = [];
bytes.push(uint8);
# String of bytes
var bytes = "";
bytes += String.fromCharCode(uint8);
my $bytes = pack('N', $uint32);
# Array of bytes
var bytes = [];
bytes.push((uint32 >> 24) & 0xFF);
bytes.push((uint32 >> 16) & 0xFF);
bytes.push((uint32 >> 8) & 0xFF);
bytes.push((uint32 ) & 0xFF);
# String of bytes
var bytes = "";
bytes += String.fromCharCode((uint32 >> 24) & 0xFF);
bytes += String.fromCharCode((uint32 >> 16) & 0xFF);
bytes += String.fromCharCode((uint32 >> 8) & 0xFF);
bytes += String.fromCharCode((uint32 ) & 0xFF);
my $bytes = pack('H*', $hex_str);
# Array of bytes
function hexToBytes(hex) {
var bytes = [];
for (var c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
}
# String of bytes
function hexToBytes(hex) {
var bytes = "";
for (var c = 0; c < hex.length; c += 2)
bytes += String.fromCharCode(parseInt(hex.substr(c, 2), 16));
return bytes;
}
首先,我告诉你 我不会说英语,但我想尝试获取有关如何将 Perl 包实施到 Javascript 中以制作 node.js 模块的信息。
为此,我想获得有关 Perl 包的更多信息。特别是我特别想知道的资料"C,H*,N"。
此外,如果我能获得有关 jspack 的更多信息,那就太好了。
提前致谢。
我实际尝试过的。
然而,它没有用。
pack 'C'
、pack 'N'
和 pack 'H*'
用于创建字节序列。
my $bytes = pack('C', $uint8);
# Array of bytes
var bytes = [];
bytes.push(uint8);
# String of bytes
var bytes = "";
bytes += String.fromCharCode(uint8);
my $bytes = pack('N', $uint32);
# Array of bytes
var bytes = [];
bytes.push((uint32 >> 24) & 0xFF);
bytes.push((uint32 >> 16) & 0xFF);
bytes.push((uint32 >> 8) & 0xFF);
bytes.push((uint32 ) & 0xFF);
# String of bytes
var bytes = "";
bytes += String.fromCharCode((uint32 >> 24) & 0xFF);
bytes += String.fromCharCode((uint32 >> 16) & 0xFF);
bytes += String.fromCharCode((uint32 >> 8) & 0xFF);
bytes += String.fromCharCode((uint32 ) & 0xFF);
my $bytes = pack('H*', $hex_str);
# Array of bytes
function hexToBytes(hex) {
var bytes = [];
for (var c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
}
# String of bytes
function hexToBytes(hex) {
var bytes = "";
for (var c = 0; c < hex.length; c += 2)
bytes += String.fromCharCode(parseInt(hex.substr(c, 2), 16));
return bytes;
}