javascript - How to render extended ASCII characters in terminal using nodejs - Stack Overflow

According to this site, ASCII extended character codes 176, 177 and 178 correspond to three characters

According to this site, ASCII extended character codes 176, 177 and 178 correspond to three characters consisting in different shades of rectangles:

Here in more detail, character 178:

Now, according to , I should be able to escape any ASCII character with a code below 256 with, for example, its hex escape sequence. So, 176 would be \xB0 in hex. But instead of getting the expected character as described above, I get "degree symbol" '°'. Degree symbol is ASCII 248, not 176, so.... what am I doing wrong?

According to this site, ASCII extended character codes 176, 177 and 178 correspond to three characters consisting in different shades of rectangles:

Here in more detail, character 178:

Now, according to https://mathiasbynens.be/notes/javascript-escapes, I should be able to escape any ASCII character with a code below 256 with, for example, its hex escape sequence. So, 176 would be \xB0 in hex. But instead of getting the expected character as described above, I get "degree symbol" '°'. Degree symbol is ASCII 248, not 176, so.... what am I doing wrong?

Share Improve this question edited Jul 2, 2017 at 21:55 jotadepicas asked Jul 2, 2017 at 21:43 jotadepicasjotadepicas 2,5033 gold badges29 silver badges48 bronze badges 1
  • The key point is "IBM developed an extension of 8-bit ASCII code, called "code page 437"". It's one of many extensions. kunststube/encoding – Bergi Commented Jul 2, 2017 at 22:04
Add a ment  | 

2 Answers 2

Reset to default 4

JavaScript uses Unicode, rather than extended ASCII. You can find the Unicode equivalent of the ASCII symbols by using String.prototype.charCodeAt(), and then output them with String.prototype.fromCharCode():

console.log("░".charCodeAt(0)); // 9617
console.log("▒".charCodeAt(0)); // 9618
console.log("▓".charCodeAt(0)); // 9619

console.log(String.fromCharCode(9617)); // ░
console.log(String.fromCharCode(9618)); // ▒
console.log(String.fromCharCode(9619)); // ▓

Hope this helps! :)

JavaScript deals in Unicode, not Extended ASCII.

U+00B0 is the degree symbol

Block elements hold positions 2580 to 259F

console.log("\u2592");

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744453856a4574999.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信