任意进制 数值 权展开式 西格玛 web html 源码

这是一段html代码 用于理解 数值权展开式的
在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>任意进制 数值 权展开式</title>
</head>
<body>
<div style="width: 100%;text-align: center;margin-top: 20rem;">
    <select name="" id="hex">
        <option value="10">十进制</option>
        <option value="16">十六进制</option>
        <option value="2" selected>二进制</option>
    </select>
    <input type="text" placeholder="数值" id="num">
    <button onclick="weight_click()">点击展开权</button>
    <table>
        <thead>
        <tr>
            <th>位数</th>
            <th>数值</th>
            <th>数权</th>
            <th>数值 * 数权</th>
        </tr>
        </thead>
        <tbody id="tbody">

        </tbody>
        <tr>
        </tr>
    </table>
</div>

<style>
    html,body{
        width: 100%;
        height: 100%;
    }
    body{
        display: flex;
        justify-content: center;
        align-content: center;
    }
    table{
        width: 50%;
        margin: auto;
    }
    tr,td,th{
        border: 1px #eee solid;
        padding: 0;
        box-sizing: border-box;
        text-align: center;
    }
</style>
<script>
    function weight_click(){
        let hexDom = document.getElementById('hex');
        let hex = hexDom.options[hexDom.selectedIndex].value;
        let val = document.getElementById('num').value;
        weight(hex, val);
    }
    function weight(hex, num){
        let temp = num.toString();
        temp = temp.split('.');
        let integer = temp[0].split('').reverse();
        let decimal = temp[1];
        let max_num = integer.length;
        let min_num = 0;
        if (decimal !== undefined) {
            decimal = decimal.split('').reverse()
            min_num = -decimal.length;
        }
        let res = [];
        for (let i = min_num; i < max_num; i++) {
            let val;
            if (i < 0) {
                val = decimal[Math.abs(i) - 1];
                res[i + Math.abs(min_num)] = {
                    math: `${val} * ${hex} ^ -${Math.abs(i)}`,
                    weight: ` ${hex} ^ -${Math.abs(i)}`,
                    number: val,
                    index: -Math.abs(i)
                }
                // res[i + decimal.length] = `Math.pow(${decimal[Math.abs(i) - 1]}, -${Math.abs(i)})`;
            }else{
                val = integer[i];
                res[i + Math.abs(min_num)] = {
                    math: `${val} * ${hex} ^ ${i}`,
                    weight: `${hex} ^ ${i}`,
                    number: val,
                    index: i
                }
                // res[i + decimal.length] = `Math.pow(${integer[i]},  ${i})`;
            }
        }
        let html = [];
        res.forEach(item => {
            html.push("<tr>")
            html.push(`<td>${item.index}</td>`)
            html.push(`<td>${item.number}</td>`)
            html.push(`<td>${item.weight}</td>`)
            html.push(`<td>${item.math}</td>`)
            html.push("</tr>")
        })
        document.getElementById('tbody').innerHTML = html.join('');
    }
    weight(10, 341.12 );

</script>
</body>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值