2017-05-16 9 views
-5

D'abord, je vais vous dire Je ne peux pas parler anglais, mais je veux essayer et obtenir des informations sur la façon d'implémenter un paquet Perl en Javascript pour faire un module node.js.javascript Perl pack

Pour ce faire, je voudrais obtenir plus d'informations sur le pack Perl. En particulier, l'information que je veux surtout savoir "C, H *, N".

Aussi, si je pouvais obtenir plus d'informations sur jspack, ce serait merveilleux.

Merci d'avance.

日本語(Japan)

+0

[pack de perldoc] (http://perldoc.perl.org/functions/pack.html) –

+1

Il y a des tutoriels en particulier conçu pour fournir des informations sur différentes langues et plus, en particulier la documentation fournie par les créateurs. SO n'est pas un site de tutoriel, s'il vous plaît essayez de demander quelque chose que beaucoup de gens peuvent bénéficier. – Zeke

Répondre

0

pack 'C', pack 'N' et pack 'H*' sont utilisés pour créer une séquence d'octets.

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; 
} 
+0

Pourquoi la downvote? – ikegami

+0

Dunno ce qui se passe ces jours-ci, mais upvoted pour compenser cela. –

+0

J'ai essayé de tester le code dans la référence. Merci à vous, le problème a été résolu. Merci beaucoup. "url de test": http: //plnkr.co/urgQPFBQ76VSJyuqJy5f –