检查是否与数字JavaScript相关联是否没有Unicode字符

发布于 2025-02-12 07:15:44 字数 368 浏览 1 评论 0原文

我正在制作一个基本转换器,可以将任何基数中的任何数字转换为其他任何基础的数字。由于碱可以是任何数字,结果可能具有代表大于10的数字的数字。为了使一个字符在最终结果中与每个数字相对应,我计划将Unicode字符分配给每个数字,对应于一个值更大的值比10使用string.fromcharcode(基本10数字代表)。但是,我注意到这种方法存在问题。在输出到HTML网页上或仅输出一个看起来像这样的空盒子时,似乎很多值都是空白的:。当我尝试通过使用if语句来查看Unicode字符的值是否等于空框或一个空字符串时,即使与数字关联的Unicode字符返回了相同的空框,它似乎总是返回false。请您帮助我了解为什么这是为什么,以及如何构建IF语句以使其像我想要的那样工作?

I am making a base converter that can convert any number in any base to the same number in any other base. Since the bases could be any number the result could have digits that represent a number greater than 10. In order to have only one character correspond to each digit in the final result, I plan to assign Unicode characters to each digit corresponding to a value greater than 10 by using String.fromCharCode(Base 10 number digit represents). However, I noticed that there was a problem with this method; It seems as if a lot of the values are blank when outputted onto the HTML webpage or only output an empty box that looks like this: . When I tried to see if the value of the Unicode character equaled the empty box or an empty string by using an if statement, it always seemed to return false, even when the Unicode character associated with the digit returned the same empty box. Please may you help me understand why this is, and how I can construct the if statement such that it will work like I want it to?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痕至 2025-02-19 07:15:44

您可以尝试一下:

function convertToDecimal(num, base) {
    return window.parseInt(num.toString(), base);
}

const binary = 10;
const base = 2;

console.log("Decimal version:", convertToDecimal(binary, base))

You could try this:

function convertToDecimal(num, base) {
    return window.parseInt(num.toString(), base);
}

const binary = 10;
const base = 2;

console.log("Decimal version:", convertToDecimal(binary, base))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文