当前位置:网站首页>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 `;
}
}边栏推荐
- 82. (cesium home) cesium points move on 3D models
- Shell编程之正则表达式(Shell脚本文本三剑客之grep)
- go入门篇 (3)
- Can you really write binary search - variant binary search
- 数据包传输:应用层-内核-硬件
- N ¨UWA: Visual Synthesis Pre-training for Neural visUal World creAtionChenfei
- Sword finger offer note: T39. Numbers that appear more than half of the time in the array
- CH340模块无法识别/烧写不进的一种可能性
- 剑指 Offer 笔记: T53 - II. 0~n-1 中缺失的数字
- 阿里云云数据库RDS版Exception during pool initialization
猜你喜欢

Adobe Audition提示 音频输入的采样率与输出设备不匹配——问题解决

Interaction free shell programming
Synchronous use reference of the new version of data warehouse (for beginners)

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

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

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

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

为什么TCP三次握手的时候ACK=Seq+1

TLC549Proteus仿真&Sallen-Key滤波器&AD736Vrms到DC转换&Proteus查看51寄存器值

暂用 Solo,博客选择困难
随机推荐
go语言之sync.Map
The first case of monkeypox in pregnant women in the United States: the newborn was injected with immunoglobulin and was safely born
JS string method summary
源码编译安装LAMP
LAN SDN hard core technology insider 25 looking forward to the future - RDMA (Part 2)
Synchronous use reference of the new version of data warehouse (for beginners)
torch‘ has no attribute ‘inference_mode‘
go入门篇 (4)
剑指 Offer 笔记: T45. 把数组排成最小的数
Greek alphabet reading
Keil MDK编译出现..\USER\stm32f10x.h(428): error: #67: expected a “}“错误的解决办法
微商的差商近似
JS字符串方法总结
剑指 Offer 笔记: T57 - I. 和为 s 的两个数字
compute_ class_ weight() takes 1 positional argument but 3 were given
剑指 Offer 笔记: T53 - I. 在排序数组中查找数字
检定和校准的区别
Idea: can't use subversion command line client: SVN solution
解决@OneToMany查询陷入循环引用问题
哈希表 详细讲解