var input_ascii = [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]; var output_str = []; for (var i = 0; i < input_ascii.length; i++) { output_str.push(String.fromCharCode(input_ascii[i])); } // "Hello, world!" console.log(output_str.join('')); var output_ascii = []; var output_hex = []; for (var i = 0; i < output_str.length; i++) { // Char to ASCII code output_ascii.push(output_str[i].charCodeAt(0)); // Char to hexadecimal number output_hex.push(output_str[i].charCodeAt(0).toString(16)); } // 72,101,108,108,111,44,32,119,111,114,108,100,33 console.log(output_ascii); // 48,65,6c,6c,6f,2c,20,77,6f,72,6c,64,21 console.log(output_hex);
[Javascript] 문자열, ASCII, 16진코드 변환
2018. 1. 15. 10:57