Wolfram Mathematica truncates initial 0:s

Nov 2010
61
0
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
 
Feb 2015
2,255
510
Ottawa Ontario
Huh? 10 = 1010; WHY d'ya want 0001010 ?
 
  • Like
Reactions: 1 person

romsek

MHF Helper
Nov 2013
6,660
2,997
California
Ignore Block[], I just use that to keep variables local to notebooks.

Clipboard01.jpg
 
  • Like
Reactions: 1 person
Nov 2010
61
0
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
Nov 2013
6,660
2,997
California
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?
 
  • Like
Reactions: 1 person
Nov 2010
61
0
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.
 
Nov 2010
61
0
Oh man you're good at this. Thank you!
 

romsek

MHF Helper
Nov 2013
6,660
2,997
California
do you understand how it works?
 
  • Like
Reactions: 1 person
Nov 2010
61
0
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!