Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Comments
Sergey Alexandrovich Kryukov 3-Mar-14 21:11pm    
Oh, how huge..! :-)
Okay, what is your declaration of vector? What does it represent? What's the problem?
—SA
Legor 4-Mar-14 4:22am    
Do you want the binary representation of the number 344 or the numbers 3, 4 and 4?

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900