Results 1 to 11 of 11
Like Tree5Thanks
  • 1 Post By DenisB
  • 1 Post By romsek
  • 1 Post By romsek
  • 1 Post By romsek
  • 1 Post By romsek

Thread: Wolfram Mathematica truncates initial 0:s

  1. #1
    Junior Member TriForce's Avatar
    Joined
    Nov 2010
    Posts
    39

    Wolfram Mathematica truncates initial 0:s

    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
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor
    Joined
    Feb 2015
    From
    Ottawa Ontario
    Posts
    1,656
    Thanks
    310

    Re: Wolfram Mathematica truncates initial 0:s

    Huh? 10 = 1010; WHY d'ya want 0001010 ?
    Thanks from TriForce
    Follow Math Help Forum on Facebook and Google+

  3. #3
    MHF Contributor
    Joined
    Nov 2013
    From
    California
    Posts
    5,694
    Thanks
    2395

    Re: Wolfram Mathematica truncates initial 0:s

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

    Wolfram Mathematica truncates initial 0:s-clipboard01.jpg
    Thanks from TriForce
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Junior Member TriForce's Avatar
    Joined
    Nov 2010
    Posts
    39

    Re: Wolfram Mathematica truncates initial 0:s

    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.

    Quote Originally Posted by DenisB View Post
    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

    Quote Originally Posted by romsek View Post
    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.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    MHF Contributor
    Joined
    Nov 2013
    From
    California
    Posts
    5,694
    Thanks
    2395

    Re: Wolfram Mathematica truncates initial 0:s

    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?
    Thanks from TriForce
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Junior Member TriForce's Avatar
    Joined
    Nov 2010
    Posts
    39

    Re: Wolfram Mathematica truncates initial 0:s

    Quote Originally Posted by romsek View Post
    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.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    MHF Contributor
    Joined
    Nov 2013
    From
    California
    Posts
    5,694
    Thanks
    2395

    Re: Wolfram Mathematica truncates initial 0:s

    Quote Originally Posted by TriForce View Post
    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.

    Wolfram Mathematica truncates initial 0:s-clipboard01.jpg
    Thanks from TriForce
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Junior Member TriForce's Avatar
    Joined
    Nov 2010
    Posts
    39

    Re: Wolfram Mathematica truncates initial 0:s

    Oh man you're good at this. Thank you!
    Follow Math Help Forum on Facebook and Google+

  9. #9
    MHF Contributor
    Joined
    Nov 2013
    From
    California
    Posts
    5,694
    Thanks
    2395

    Re: Wolfram Mathematica truncates initial 0:s

    do you understand how it works?
    Thanks from TriForce
    Follow Math Help Forum on Facebook and Google+

  10. #10
    Junior Member TriForce's Avatar
    Joined
    Nov 2010
    Posts
    39

    Re: Wolfram Mathematica truncates initial 0:s

    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!
    Follow Math Help Forum on Facebook and Google+

  11. #11
    MHF Contributor
    Joined
    Nov 2013
    From
    California
    Posts
    5,694
    Thanks
    2395

    Re: Wolfram Mathematica truncates initial 0:s

    Wolfram Mathematica truncates initial 0:s-clipboard01.jpg
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 2
    Last Post: Sep 25th 2011, 05:19 PM
  2. Beginner Help with Wolfram Mathematica pl!
    Posted in the Math Software Forum
    Replies: 8
    Last Post: Apr 26th 2011, 11:58 AM
  3. Wolfram announcement about Mathematica 8
    Posted in the Math Forum
    Replies: 0
    Last Post: Nov 17th 2010, 08:37 AM
  4. help me in Wolfram Mathematica
    Posted in the Calculus Forum
    Replies: 1
    Last Post: Mar 1st 2010, 11:56 PM
  5. Wolfram's Mathematica
    Posted in the Math Software Forum
    Replies: 9
    Last Post: Aug 7th 2006, 09:04 PM

Search Tags


/mathhelpforum @mathhelpforum