将数字向量转换为二进制 [英] Converting vector of digits to binary

查看:190
本文介绍了将数字向量转换为二进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我知道如何将int转换为二进制,但我不知道如何将数字向量转换为二进制数。



说我有以下向量:



[3] [4] [4]我想转换为二进制,我该怎么做?



4是100

40是101100

300是100101100



344是101011000



如果我把它们加起来我得到一个二进制数,但复杂性太大了。

Ok, I know how to convert an int to a binary, but I don't know how to convert a vector of digits into a binary number.

Say I have the following vector:

[3][4][4] and I want to convert to binary, how do I do it?

4 is 100
40 is 101100
300 is 100101100

344 is 101011000

if I add them up I get a binary number, but the complexity is too huge.

推荐答案

我也很困惑,首先是因为你说上面的40是101100



我不明白,因为40 = 101000 in二元所以你犯了错误吗?



44 = 101100二进制所以你的意思是44并写40?



混淆的第二个来源与其他回复相同如果你已经可以对二进制进行int则没有什么可以添加



直接转换为344,你得到什么y你想要101011000或你再次犯了错误,你只能进行字节转换而不知道如何将它扩展为整数和长数?



你说引用好的,我知道如何将int转换为二进制,所以如果你知道为什么你在344范围内挣扎,那就是在int范围内。



您可能想要的另一种选择是这样的数字,我已经将它们写成了由点分隔的半字节,上面提到了这些数字



0011。 0100 0100

3 4 4



所以344 => 0011 0100 0100



您需要澄清您的意思和尝试。
I too am confused, firstly because you said this above "40 is 101100"

I don't get that because 40 = 101000 in binary so did you make a mistake?

44 = 101100 in binary so did you mean 44 and write 40?

The second source of confusion is the same as other replies if you can already do int to binary then there is nothing to add

Do the direct conversion on 344 and you get what you want 101011000 or again have you made an error in what you said and you can only do byte conversion and don't know how to extend it to integers and longs?

You said quote "Ok, I know how to convert an int to a binary" so if you know that why are you struggling with 344 that is well within int range.

The alternative you could be possibly wanting is numbers like this, I have written them as nibbles seperated by dots which legor asks above

0011 . 0100 . 0100
3 4 4

So 344 => 0011 0100 0100

You need to clarify what you mean and are trying to do.


这篇关于将数字向量转换为二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆