当前位置:网站首页>Conversion between multiple bases
Conversion between multiple bases
2022-07-27 11:52:00 【Dust escape】
What is the base
- Base is the carry counting system , Artificially defined calculation method with carry
- For any system ---X Base number , It means that the number operation on each bit is every X Into one ( Add and subtract in the same base )
notes : There are counting methods without carry , For example, the original twine counting method , Commonly used in singing “ just ” Word count , And similar tally mark Count
Basic concepts
| name | describe | describe | Regular expressions |
| Binary system | 0~1 To represent the number of | Two states of on-off ( Binary is used in computer field for technical reasons ) | /^[0,1]*$/ |
| Quaternary | 0~3 To represent the number of | Quaternary is people's description of the objective existence of climate change around the earth , Turn the revolution into four areas , It is four o'clock ( spring, summer, autumn and winter ), Expand the chaotic binary world into a quaternary world ( For heredity 、 The data transfer 、 Base conversion, etc ) | /^[0-3]*$/ |
| octal | 0~7 To represent the number of | electronic technique 、 Computer programming and other fields are used together with binary | /^[0-7]*$/ |
| Decimal system | 0~9 To represent the number of | As a counting method | /^[0-9]*$/ |
| Hexadecimal | 0~15 To represent the number of | electronic technique 、 Computer programming and other fields are used together with binary . 0~9、10=>A、11=>B、12=>C、13=>D、14=>E、15=>F | /^[0-9A-f]*$/ |
| 32 base | 0~31 To represent the number of | 0~9、10=>A、11=>B、12=>C、13=>D、14=>E、15=>F、16=>G、17=>H、18=>I、19=>J、20=>K、21=>L、22=>M、23=>N、24=>O、25=>P、26=>Q、27=>R、28=>S、29=>T、30=>U、31=>V | /^[0-9A-u]*$/ |
Method
function regular(param1, param2, param3) {
let arr = [2, 4, 8, 10, 16, 32];
param3 = param3 ? param3 : 10;
let obg = [/^[0,1]*$/, /^[0-3]*$/, /^[0-7]*$/, /^[0-9]*$/, /^[0-9A-f]*$/, /^[0-9A-u]*$/]
let reg = obg[`${arr?.indexOf(param3)}`];
let nub = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V'];
if (reg.test(param1)) {
let param = param1.toString().split('');
let num = param.reduce((vauel, item, index) => (vauel += nub.indexOf(item) * (param3 ** ((param.length - index) - 1))), 0);
const turn = (num1, num2) => {
let num = Math.floor(num1 / num2);
let value = num1 - num2 * num;
return `${num ? turn(num, num2) : ''}${nub[value]}`;
}
return turn(num, param2);
} else {
return ` Choose the right one ${param3} Binary operation `;
}
}边栏推荐
- Beyond Compare 3 下一个差异段/向下搜索箭头 找不到了
- Principle of control system based on feedback rate
- Solution of digital tube flash back after proteus8 professional version cracking
- Database cli tool docker image
- LAN SDN hard core technology insider 24 outlook for the future - RDMA (middle)
- w.r.t. ; i.e.;etc.;e.g.是什么意思
- A possibility that ch340 module cannot be recognized / burned
- 基于反馈率的控制系统原理
- Arduino常见供电问题与解决
- STS下载教程(include官网无法下载解决方案)
猜你喜欢
意外收获史诗级分布式资源,从基础到进阶都干货满满,大佬就是强!

Temporary use of solo, difficult choice of Blog

Proteus8专业版破解后用数码管闪退的解决

广东:剧本杀等新行业新业态场所,消防安全监管不再“缺位”

The first case of monkeypox in pregnant women in the United States: the newborn was injected with immunoglobulin and was safely born

Idea: can't use subversion command line client: SVN solution

Could not load dynamic library ‘libcudnn.so.8‘;

Shell脚本文本三剑客之sed

Shell编程之正则表达式(Shell脚本文本三剑客之grep)

Keil MDK编译出现..\USER\stm32f10x.h(428): error: #67: expected a “}“错误的解决办法
随机推荐
Temporary use of solo, difficult choice of Blog
Matlab S-function详解
LAN SDN technology hard core insider 11 the key of cloud convergence CP -- hierarchical port binding
origin如何作一张图中多张子图是柱状图(或其他图)
[untitled] multimodal model clip
V-show failure
LAN SDN hard core technology insider 25 looking forward to the future - RDMA (Part 2)
Proteus8专业版破解后用数码管闪退的解决
[machine learning whiteboard derivation series] learning notes - probability graph model and exponential family distribution
Could not load dynamic library ‘libcudnn.so.8‘;
日本福岛废堆安全监视协议会认可排海计划“安全”
Shell编程之正则表达式(Shell脚本文本三剑客之grep)
快抖抢救“失意人”
LAN SDN technology hard core insider 12 cloud CP's daily love - hardware vxlan forwarding plane
Synchronous use reference of the new version of data warehouse (for beginners)
Pytorch shows the summary like tensorflow
箱型图介绍
Detailed explanation of hash table
Leetcode 01: t1. sum of two numbers; T1108. IP address invalidation; T344. Reverse string
Unexpected harvest of epic distributed resources, from basic to advanced are full of dry goods, big guys are strong!