Forums > MaxMSP

Binary to Decimal

August 27, 2008 | 4:11 am

Hi

I was wondering if anyone has objects that I could use that allows the conversion of Decimal numbers to Binary ?

Cheers
Guy


August 27, 2008 | 5:14 am

What do you intend to do with the binary data? If it’s just for display purposes, the standard number box can display as binary.


August 27, 2008 | 12:16 pm

Just to clarify: numbers in Max are *always* binary (they can’t be anything else internally). And they are *always* displayed in decimal (with the exception of the formatting options in numbox and flonum).


August 27, 2008 | 12:41 pm

On 2008 Aug 26, at 11:11 PM, Guy Ben-Ary wrote:

> I was wondering if anyone has objects that I could use that allows
> the conversion of Decimal numbers to Binary ?

Hi. There is an object in Tap.Tools called tap.bits which converts
between lists of ones and zeros and integers. The URL is below.

best,
Tim
____________________________________
Tap.Tools – Objects for Max, MSP, and Jitter

http://electrotap.com/taptoolsmax/


August 27, 2008 | 12:59 pm

Here’s your answer.

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 196 176 62 196617 prepend set;
#P message 196 197 63 196617 1 0 1 1 1 1;
#P number 196 134 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 196 155 71 196617 js dectobin.js;
#P connect 1 0 0 0;
#P connect 0 0 3 0;
#P connect 3 0 2 0;
#P window clipboard copycount 4;

I can do a binary to decimal converter too if you wish?


August 27, 2008 | 1:03 pm

You’ll can put [zl rev] after it depending if you want the MSB of the LSB first.


August 27, 2008 | 1:35 pm

Output is always MSB first and input should always be MSB first though you can change these around with [zl rev].

Output in binary is as a list, input should be as a list too. The patch show the usage. Hopefully this helps?

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 225 45 70 196617 1 1 1 0 1 0 1;
#P newex 75 66 82 196617 prepend decimal;
#P message 178 45 43 196617 1 0 1 0;
#P message 160 45 14 196617 1;
#P newex 160 66 77 196617 prepend binary;
#P newex 124 120 62 196617 prepend set;
#P message 124 141 63 196617 10;
#P number 75 45 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 124 99 71 196617 js dectobin.js;
#P connect 1 0 7 0;
#P connect 7 0 0 0;
#P connect 4 0 0 0;
#P connect 0 0 3 0;
#P connect 3 0 2 0;
#P connect 8 0 4 0;
#P connect 6 0 4 0;
#P connect 5 0 4 0;
#P window clipboard copycount 9;


August 27, 2008 | 1:58 pm

This .js patch yields a ’1′ – on my system – when a ’0′ decimal is input.

On Wed, Aug 27, 2008 at 9:03 AM, fairesigneaumachiniste
wrote:

>
> You’ll can put [zl rev] after it depending if you want the MSB of the LSB
> first.
>


August 27, 2008 | 2:34 pm

Here’s an abstraction that takes binary numbers as lists and converts them. It uses only standard objects so doesn’t require a js or any externals.

lh

– Pasted Max Patch, click to expand. –

August 27, 2008 | 3:32 pm

Nice patch, thereishopeforus!

Here’s the same patch, but I’ve made a few cosmetic simplifications.

Zachary

– Pasted Max Patch, click to expand. –

August 27, 2008 | 3:37 pm

Whoops! Thanks for that. I didn’t test extensively (i.e. not at all).

So, to make up for that I give you the new version. Numbers no longer need to be a list if they are in binary format. Just send a message like this [binary 101101] for example and it will convert to decimal. Also, sending [decimal 10] will output 1010 as a message, not as a list.

And the right output also outputs the value as Hex.

Hope this is useful.

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 209 140 50 196617 a;
#P message 124 140 50 196617 10;
#P newex 209 120 62 196617 prepend set;
#P newex 124 120 62 196617 prepend set;
#P message 113 45 14 196617 0;
#P message 267 45 14 196617 0;
#P message 213 45 52 196617 1110101;
#P newex 75 66 82 196617 prepend decimal;
#P message 176 45 34 196617 1010;
#P message 160 45 14 196617 1;
#P newex 160 66 77 196617 prepend binary;
#P number 75 45 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 124 99 95 196617 js dectobin.js;
#P connect 1 0 5 0;
#P connect 8 0 5 0;
#P connect 2 0 0 0;
#P connect 5 0 0 0;
#P connect 0 0 9 0;
#P connect 9 0 11 0;
#P connect 3 0 2 0;
#P connect 4 0 2 0;
#P connect 6 0 2 0;
#P connect 7 0 2 0;
#P connect 0 1 10 0;
#P connect 10 0 12 0;
#P window clipboard copycount 13;


August 27, 2008 | 4:23 pm

Ah [listfunnel]!

I can never decide whether I love it or hate it when i find an object that does in one step what I’ve been doing in twenty, especially if it’s been staring me in the face for a while.

Also the last bit can be replaced by [zl sum].

lh

– Pasted Max Patch, click to expand. –

August 27, 2008 | 4:47 pm

On Aug 27, 2008, at 9:23 AM, Luke wrote:
> I can never decide whether I love it or hate it when i find an
> object that does in one step what I’ve been doing in twenty,
> especially if it’s been staring me in the face for a while.

If you’re willing to install the Jasch objects, there’s bitlist which
does bidirectional conversion. There are many useful objects in this
collection.

http://www.jasch.ch/dl/default.htm

-C

Chris Muir
cbm@well.com

http://www.xfade.com


August 27, 2008 | 4:52 pm

Yes, the jasch objects are great.


August 28, 2008 | 12:00 am

Here is a slight modification so that it only outputs when it has finished summing the values. Otherwise, it outputs an integer for every bit. Also: the expr still works if you don’t unpack the list, and I took out the "1" from the listfunnel, so the "- 1" is no longer necessary.

– Pasted Max Patch, click to expand. –

Quote: Zachary Seldess wrote on Wed, 27 August 2008 11:32
—————————————————-
> Nice patch, thereishopeforus!
>
> Here’s the same patch, but I’ve made a few cosmetic simplifications.
>
> Zachary


August 28, 2008 | 4:38 am

Luke schrieb:
> Here’s an abstraction that takes binary numbers as lists and converts
> them. It uses only standard objects so doesn’t require a js or any
> externals.

And this is my version of the same…

– Pasted Max Patch, click to expand. –


Stefan Tiedje————x——-
–_____———–|————–
–(_|_ —-|—–|—–()——-
– _|_)—-|—–()————–
———-()——–www.ccmix.com


September 29, 2009 | 5:56 am

Hi,

Just a follow up. I’m rather (extremely) new to Max MSP, but I can’t figure this out.

I want to take a binary list and essentially chunk it into bytes. Another words, assuming I have some arbitrarily large list of bits (8 * X bytes), how do I get it to operate on the first 8 bits, then the next 8 bits, then the next, etc.

Assume the list in byte order. This means that the first 8 bits in the list should become the first byte in the resulting list. If there were 64 bits in the list, the result should be 8 bytes long.

Here’s a visual representation. It doesn’t work as it just creates an int from the entire binary string. It shows a 64 bit list and I’ve for illustration purposes created a fake output of 8 bytes that represents the values of the bits (top row of bit = first byte in output message.)

Any help would be appreciated. Thanks.

– Pasted Max Patch, click to expand. –

September 29, 2009 | 6:09 am

Figured it out.

used ‘zl iter’ with a chunk size of 8.

– Pasted Max Patch, click to expand. –

September 29, 2009 | 7:06 am

i also have an abstraction which does this, but it outputs
the "binary" digits to individual outputs – because as
you might have noticed, you can not display 7777777 as "binary"
in max, it is simply a too long number, only up to 256 it will
fit into 8 digits.


October 27, 2009 | 7:04 am

Problem with converting large binary list in chunks.

Hi, was using the some of the above binary to int converters on a largish list and I’m getting inconsistent results with the output.

I’m new to this, so I’m having a hard time figuring out why it’s not working as expected. On the patch below is a 24×16 binary list. I iterate 4 bits at a time into "bintoi" and should get 96 integers out. The results should be what you see in the "Expected Result" message, but they are not.

Can’t figure out what I’m doing wrong. Any thoughts?

(This is an example. In the real life version, the binary list is being created by jit.spill from a matrix via an expression.)

– Pasted Max Patch, click to expand. –

October 27, 2009 | 8:54 am

You’re feeding more numbers to zl iter then the default size. Make it a [zl 384 iter 4] to change that default. Below are by the way other ways of making the conversion without math.

– Pasted Max Patch, click to expand. –

October 28, 2009 | 3:11 am

Thanks for the help. It totally fixed the problem I was having.


Viewing 22 posts - 1 through 22 (of 22 total)