简体   繁体   English

JavaScript 中是否有字节大小的数据类型?

[英]Is there byte sized data type in JavaScript?

I am currently trying to use Node to create a bitmap image.我目前正在尝试使用 Node 创建 bitmap 图像。 I have been using String.fromCharCode() to add bytes however I quickly realized this does not work.我一直在使用 String.fromCharCode() 添加字节但是我很快意识到这不起作用。 For example, if I wanted to create a file containing the hex values FF, it makes sense to me to use the code bellow.例如,如果我想创建一个包含十六进制值 FF 的文件,那么使用下面的代码对我来说很有意义。

test = String.fromCharCode(255);测试 = String.fromCharCode(255);

When I examine the file it creates 2 bytes instead of one, 0xC3, 0XBF.当我检查文件时,它会创建 2 个字节而不是 0xC3、0XBF。

Is there a better way of doing this?有没有更好的方法来做到这一点?

Use the Buffer object and then the readInt8() and writeInt8() function使用缓冲区object 然后readInt8()writeInt8() function

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM