# Wolfram Mathematica truncates initial 0:s

#### TriForce

I'm trying to convert a list with numbers into a string with binary values.

In[168]:= x={10, 10};
IntegerString[x,2]
z=StringJoin[IntegerString[x,2]]
Out[169]= {1010,1010}
Out[170]= 10101010

The desired result would be:
Out[169]= {0001010, 0001010}
Out[170]= 00010100001010

#### DenisB

Huh? 10 = 1010; WHY d'ya want 0001010 ?

1 person

#### romsek

MHF Helper
Ignore Block[], I just use that to keep variables local to notebooks.

1 person

#### TriForce

To describe the whole problem I'm trying out RSA encryption and want to convert a text string to a number.
So i convert each letter into a ascii number and then convert each number into binary form.

Huh? 10 = 1010; WHY d'ya want 0001010 ?
It's needed to keep the binary intact, the binary codes can be seen here:

https://en.wikipedia.org/wiki/ASCII

Ignore Block[], I just use that to keep variables local to notebooks.
Thanks for the suggestion, although it works for this specific example it can't be applied generally.
Basically we have a 7 bit binary space for each letter, ranging from 0000001 to 1111111.
Problem is all initial zeroes get truncated in conversion.

#### romsek

MHF Helper
so a routine to take a list of 2 non-negative integers, convert them to 7 bit binary, padding to 7 bits as necessary, and then concatenating them?

1 person

#### TriForce

so a routine to take a list of 2 non-negative integers, convert them to 7 bit binary, padding to 7 bits as necessary, and then concatenating them?
The list will contain many non-negative integers, other than that you're spot on.

#### romsek

MHF Helper
The list will contain many non-negative integers, other than that you're spot on.
This should work with an arbitrary list of char codes.

1 person

#### TriForce

Oh man you're good at this. Thank you!

#### romsek

MHF Helper
do you understand how it works?

1 person

#### TriForce

Sort of, I'm very new to mathematica and not sure about some of it's syntax and operators.

But overall yes, you create a function that checks the input length of each element in the list and adds up to 7 zeroes. Then concatenates it to a larger string.

Thanks!