当前位置:网站首页>Get string byte size
Get string byte size
2022-06-21 05:51:00 【Pig in August】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
function getSize(str) {
const bytes = unescape(encodeURIComponent(str)).length; // Get bytes
const bytes1 = new Blob([str]).size; // Get bytes
console.log(" Byte size ...", bytes, bytes1);
const size = convert("B", bytes);
return `${str} Character size :${size}`;
}
function convert(unit, bytes) {
const units = ["B", "KB", "MB", "GB", "TB"];
const i = units.indexOf(unit);
const size = (bytes / pow1024(i)).toFixed(2); // Bytes to other units
return `${size} ${units[i]}`;
}
// Find the power
function pow1024(num) {
return Math.pow(1024, num);
}
// 1 Bytes are 8 Binary bits (8 Binary bits make up 1 Bytes ), namely 1Byte=8bit( A combination of eight bits , share 256 Circuit states ).
// 1 A digital =1 English letters ( character )=1 byte (Byte), That is, a standard English letter is a byte , It has 8 A bit (bit),( Such as A by 10D, use 00001010 To express ,8 Binary bits ).1 The Chinese characters =2 Bytes , That is, a standard Chinese character has 2 Bytes ,8 individual bit A byte , That is to say, in the computer 1 A Chinese character should be used 16 individual bit To express . In addition, Chinese punctuation marks account for 2 Bytes , English Punctuations (,.?!%&+-*/), Occupy 1 Bytes , Chinese Ellipsis (……) Hekuo ( Broken fold ) Number (——) Each account 4 Bytes . The size of a file is actually the number of bytes the file content actually has , It uses Byte Is the unit of measurement , As long as the file content and format do not change , The file size will not change .
console.log(getSize("aaa"));
console.log(getSize(123));
console.log(getSize(" Blue forget the machine "));
// Reference documents :
// 1. https://segmentfault.com/q/1010000007847667
// 2. https://blog.csdn.net/qq_23994787/article/details/86609659
// 3. https://aixiaodou.blog.csdn.net/article/details/108885082?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-108885082-blog-106854329.pc_relevant_downloadblacklistv1&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-108885082-blog-106854329.pc_relevant_downloadblacklistv1&utm_relevant_index=1
</script>
</body>
</html>
边栏推荐
- build opencv3.4.16
- CANopen COB-ID 使能PDO功能
- 五分钟搞定软件设计师下午题
- [UVM basics] seed value setting in makefile
- Embedded development experience of RTOS group
- 基于CNN的音乐流派分类
- Emotron ilton Soft Starter repair msf370 / msf450
- Global and Chinese markets without regenerative dryers 2022-2028: Research Report on technology, participants, trends, market size and share
- 应用在电子产品背光显示中的模拟环境光传感芯片
- armcm3权威指南笔记----arm编程中地址未对齐方面的影响
猜你喜欢

Factory pattern

工业级的内存拷贝函数实现

Attention based seq2seq model

Sentinel熔断限流真的太丝滑了

398-哈希表(242.有效的字母异位词 & 349. 两个数组的交集 & 202. 快乐数)

Distributed transaction of microservices Seata

Emotron伊爾通軟啟動器維修MSF370/MSF450

Sentinel fusing and current limiting is really too slippery

Cross chain revelation: has your assets really been transferred in the process of cross chain?

vscode+platformIO开发STM32(七)
随机推荐
These classic software, which was once very popular, are still fresh in my memory now
ssh-copy-id 批量免密脚本
Oracle数据库启停
Sentinel熔断限流真的太丝滑了
CANopen COB-ID 使能PDO功能
Global and Chinese markets of tunable lasers 2022-2028: Research Report on technology, participants, trends, market size and share
DP背包总结
数字式温度传感器工作原理以及测温原理分析
Object. Assign() object merge and object Keys() get the object name
[Prometheus] an optimization record of Prometheus Federation
js Promise的运用
Implementation of industrial memory copy function
Merge syntax of Oracle notes
Research and Analysis on the current situation of China's fluorenone market and forecast report on its development prospect (2022)
[graduation season] nine year program ape has something to say
Arm authoritative guide and our group's project notes
OracleLinux6.5图形化安装Oracle11g
js 封装函数,多次调用结果追加
Research and Analysis on the current situation of LBS market in China and forecast report on its development prospect (2022)
Attention based seq2seq model