binary 相关问题

二进制,基数为2的数字系统,使用两个符号表示数字:0和1.对于编译的计算机程序,请改用“可执行”标记。

用非常大的数字称赞AKS c++

我们有一个项目,我们必须在 C++ 中实现 AKS,输入是 128 位到 512 位数字(输入是十六进制,我将其转换为二进制)。 我们只能使用C++ STL。我想知道是否

回答 1 投票 0

将 BigInteger 二进制转换为 BigInteger 数字?

目前我正在使用长整数类型。我使用以下命令来转换二进制/数字: Convert.ToInt64(BinaryString, 2); //将基数为2的二进制字符串转换为数字 Convert.ToString(LongN...

回答 2 投票 0

在 C# 中将 BigInteger 二进制转换为 BigInteger 数字?

目前我正在使用长整数类型。我使用以下命令来转换二进制/数字: Convert.ToInt64(BinaryString, 2); //将基数为2的二进制字符串转换为数字 Convert.ToString(LongN...

回答 2 投票 0

JS中如何将十进制转换为二进制?

可以通过以下方式将二进制转换为十进制: var 二进制=“110”; var int = parseInt(binary, 2); document.getElementById("结果").innerHTML = int; 可以通过以下方式将二进制转换为十进制: var binary = "110"; var int = parseInt(binary, 2); document.getElementById("results").innerHTML = int; <div id="results"></div> 但是,我如何做相反的操作:将 int 转换为二进制? let decimal = prompt('please insert decimal number'); console.log(Number(decimal).toString(2)); Dec 到 Bin:原始(按位) /** * Dec to Bin * with bitwise operations * * Eudes Serpa M. **/ const numberToConvert = 5; const numberOfBits = 32; // 32-bits binary const arrBitwise = [0]; // save the resulting bitwise for (let i=0; i<numberOfBits; i++) { let mask = 1; const bit = numberToConvert & (mask << i); // And bitwise with left shift if(bit === 0) { arrBitwise[i] = 0; } else { arrBitwise[i] = 1; } } const binary = arrBitwise.reverse().join(""); console.log(`This is the resulting binary: ${binary}`) console.log(`This is the verification ${parseInt(binary, 2)}`); 说明: 第 2 行:我们指定组成生成的二进制文件的位数。 第 3 行:我们定义一个数组,用于保存位级操作产生的位。最后,这将是我们生成的二进制文件(反转它) For:用于“创建”二进制位。 掩码:表示我们在位级别移位到的数字(1 进行 AND 运算并获得要转换的数字 1 中的位)。 bit:执行运算的结果位,例如: 位数 = 3; 掩码= 1; for (i = 0 -> 31) { // 32 位 // Explanation of the operation to obtain the bit in position i // ---- For i = 0; 1. mask << 0 = ...0001 (a 1 in decimal), since it does not do any shifting. 2. 3 & 1 /* At the bit level we have to 3 = ...0011 1 = ...0001, so when doing the AND operation at the bit level, we have to: 0011 &0001 ------ 0001 === 1 decimal */ // bit then takes the value resulting from the previous operations. This is: bit = 1; // The if is not meet, so it enters the else: arrBitwise[0] = 1; // ---- For i = 1; 1. mask << 1 = ...0010 (a 2 in decimal) 2. 3 & 2 /* At the bit level we have to 3 = ...0011 2 = ...0010, so when doing the AND operation at the bit level, we have to: 0011 &0010 ------- 0010 === 2 decimal */ // bit then takes the value resulting from the previous operations. This is: bit = 2; // The if is not meet, so it enters the else: arrBitwise[1] = 1; // ----- For i = 2; 1. mask << 2 = ...0100 (a 4 in decimal) 2. 3. 4 /* At the bit level we have to 3 = ...0011 4 = ...0100, so when doing the AND operation at the bit level, we have to: 0011 &0100 ------- 0000 === 0 decimal */ // bit then takes the value resulting from the previous operations. This is: bit = 0; // The if meet, so: arrBitwise[2] = 0; } 因此,arrBitwise 将是: arr按位 = [1, 1, 0, 0, ..., 0]; arrBitwise.reverse() // [0, ..., 0, 0, 1, 1] 与.join() "0...0011" 用二进制表示3。 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Left_shift 二进制和十进制都是具有不同基数的数字的字符串表示形式。 这就是为什么我们在从字符串获取数字时需要指定基数: binary = '10101' decimal = '21' Number.parseInt(binary, 2) === Number.parseInt(decimal, 10) // true 同样,当我们将数字转换为字符串时,我们可以(但不必)指定基数: n = 21 n.toString(2) // '10101' Radix 在这里是可选的,省略时等于 10: n = 21 n.toString() // '21' 请参阅 Number.prototype.toString() 了解更多详细信息。 您可以尝试使用无符号右移运算符。 >>> 0运算符对数字没有影响,但会给出二进制等价值。 您可以运行下面的代码片段(如果尝试使用-6,输出应为 11111111111111111111111111111010)。 //Here you can test it directly var number = -6; alert((number >>> 0).toString(2)); //Or you can do it with a function function dec2Bin(dec) { return (dec >>> 0).toString(2); } alert(dec2Bin(-6)); var x = 6; console.log(x.toString(2)); 代码在注释中有解释 const input = 18; const converted = deciToBinary(18, '') // function to convert decimal to binary const countOnes = countOne(converted); // function to count the occurence of 1s console.log(countOnes); function countOne(input) { const strlen = input.length; let count = 0; for (let i = 0; i < strlen; i++) { if (parseInt(input[i])) { count++ } } return count; } function deciToBinary(input, output) { const reminder = input % 2; // find the reminder const quotient = parseInt(input / 2); // find the quotient if (quotient > 1) { // if quotient is > 1 i.e not 0 or 1 output += reminder; // add the reminder to the string return deciToBinary(quotient, output); // using recursive function concept, recall the function } output += reminder; // add the reminder output += quotient; // add the quotient const binary = output.split('').reverse().join(''); // reverse the string return binary; }

回答 6 投票 0

如何仅获取二进制文件的前十个字节

我正在编写一个 bash 脚本,需要获取文件的标头(前 10 个字节),然后在另一个部分中获取除前 10 个字节之外的所有内容。这些是二进制文件,可能有...

回答 4 投票 0

如何在C中将二进制形式的1改为0

我不知道如何将x的二进制形式中的任何连续的1更改为0(连续的1意味着一组1包含多个1)。 问题规格: 允许的运算符: ! 〜&a...

回答 1 投票 0

查找最大子树(具有最大顶点)(二叉搜索树)

对于给定的二叉搜索树,找到每个非叶顶点满足条件的顶点数最多的最大子树: • 左子树的高度不同于

回答 1 投票 0

作为二元变量处理

有人可以帮我解决这个错误吗? 错误:处理必须是二元变量。 尝试继续运行以下代码行,但无法弄清楚问题出在哪里以及为什么......

回答 1 投票 0

python递归二分查找问题中的类型错误

类解决方案: def search(self, nums: List[int], target: int) -> int: 左,右 = 0,len(nums) - 1 离开时 <= right: curr_ind = (right+left)//2 ...

回答 2 投票 0

如何调试这个用于二分搜索的Javascript代码

这段代码是实现二分查找。但是,它不起作用并返回未定义。我不知道为什么会出错,请帮助我! 函数binarySearch(arr, key) { 让低= 0; 让...

回答 1 投票 0

“bit_ceil”未在此范围内声明

我正在尝试使用 bit_ceil(),我包含了 < bit > 标头,并使用了 std 命名空间(我知道这不是一个好的做法,但我在这里这样做是为了解决问题) 但当我尝试时...

回答 1 投票 0

在汇编8086中从十进制转换为二进制时出现输出问题

我正在汇编 8086 中编写一段代码,您必须输入一个十进制数并将其转换为二进制数,但我面临输出问题。输出从数字 1 到 2559 都很好,但是...

回答 1 投票 0

二进制负数(8 位)

我应该使用 (i) 补码和 (ii) 补码将以下负数转换为 8 位二进制: -76 -203 -18 -177 我知道如何做 -76 和 -18... •-76 在双...

回答 1 投票 0

编写一个程序,采用正数并将其输出为二进制

编写一个程序,以正整数作为输入,并输出 由 1 和 0 组成的字符串,表示二进制整数。示例输出:5 是 101 二进制。当该值小于或等于 0 时,输出...

回答 1 投票 0

如何将这个base64行缩短4个字符?

我正在使用几何破折号专用服务器,我需要用我自己的数据库链接(aHR0cDovL3d3dy5ib29tbGluZ3MuY29tL2RhdGFiYXNl)替换原始数据库链接,但每次我对数据库链接进行编码时

回答 1 投票 0

公式 x & (x - 1) 是如何计算的?

来自《黑客之乐:第二版》: 这里的公式看起来有点尴尬。当 x 小于 1 时,如何从 1 个向量(大概是 0x1111 1111)中减去某个 x 向量? (如:(如...

回答 3 投票 0

如何从远程服务器获取.pdf文件到本地?

我有远程虚拟服务器(oracle linux 7.6)包含.pdf文件,我用Firefox打开它。 远程服务器阻止外部网络。 但我可以选择将字符串从远程复制到本地。 如何获得...

回答 1 投票 0

KOTLIN - 如何将消息长度表示为 2 个二进制字节

我在构建 ECR(电子收银机)和 Android POS 之间的集成时遇到问题。我正在开发 android POS,我想计算消息大小并将其添加到...

回答 2 投票 0

十进制转二进制数表示逻辑错误

我被指示编写一个程序,将十进制表示为 32 位二进制数。我的代码可以正常工作,编译正常,但输出不正确。我已经使用了所有资源...

回答 1 投票 0

如何对来自函数的数字求平方?

我是javascript和编码的新手。我不能取来自函数的数字的平方。我在下面写下了我想要做的事情。谢谢大家。 // 二进制转十进制 // (100110)2 > (1 × 2⁵) + (0...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.