当前位置:网站首页>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 `;
}
}边栏推荐
- Several banks adjusted the redemption rules of cash management financial products: the confirmation time limit of redemption changed from "t+0" to "t+1"
- JS parasitic combinatorial inheritance
- 微商的差商近似
- go入门篇 (2)
- makefile模板
- [unity entry program] creator kitfps: first person shooting 3D game
- omitempty在go中的使用
- LNMP architecture setup (deploy discuz Forum)
- IDEA: Can‘t use Subversion command line client:svn 解决方案
- compute_ class_ weight() takes 1 positional argument but 3 were given
猜你喜欢

解决方案:idea project没有显示树状图

你真的会写二分查找吗——变种二分查找

【无标题】多模态模型 CLIP

Shell脚本文本三剑客之awk

Source code compilation and installation lamp
![[machine learning whiteboard derivation series] learning notes - support vector machine and principal component analysis](/img/54/dc232f737da99c7097c395a326e74f.png)
[machine learning whiteboard derivation series] learning notes - support vector machine and principal component analysis

解决@OneToMany查询陷入循环引用问题

Beyond compare 3 next difference segment / down search arrow not found

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

Principle of control system based on feedback rate
随机推荐
Principle of PWM and generation of PWM wave
Shell script text three swordsman awk
剑指 Offer 笔记: T53 - I. 在排序数组中查找数字
LAN SDN technology hard core insider 13 from LAN to Internet
Weibo comment crawler + visualization
Database cli tool docker image
torch‘ has no attribute ‘inference_mode‘
Vscode removes style / syntax highlighting / code highlighting / black background when copying code
Leetcode 04: T26. Delete duplicate items in the sorting array (simple); Sword finger offer 67. convert the string to an integer (medium); Interview question 01.08. zero matrix (simple)
Source code compilation and installation lamp
Several banks adjusted the redemption rules of cash management financial products: the confirmation time limit of redemption changed from "t+0" to "t+1"
NPM step pit
Shell script text three swordsmen sed
go 用本地代码replace
Keil MDK编译出现..\USER\stm32f10x.h(428): error: #67: expected a “}“错误的解决办法
Beyond Compare 3 下一个差异段/向下搜索箭头 找不到了
Principle of control system based on feedback rate
【无标题】多模态模型 CLIP
TapNet: Multivariate Time Series Classification with Attentional Prototypical Network
Sword finger offer notes: t58 - I. flip word order