## Trouble with bitwise operations..

Oct 29 2019 | 1:19 pm
I'm struggling how to do this calculation in Max:
My program will return a "3", meaning that the 3rd bit in an 8-bit number is "on" (100, or 4) . A "4" means the 4th bit is "on" (1000, or 8), and so on. But I'm having trouble converting the initial number that signals which bit is on (3 or 4 in the above examples) to its binary or decimal version (again, 100/4 or 1000/8 in the above examples). Any thoughts?

• Oct 29 2019 | 2:48 pm
Maybe like this :
• Oct 29 2019 | 3:47 pm
PDELGES, that is perfect! One more question: do you know of a way to make it so that the binary number being output is always being expressed as an 8-bit number (e.g. "100" = "00000100")
• Oct 29 2019 | 4:37 pm
Be carefull, the patch I sent displays a number as a binary, but if you need a message that looks like a binary, then you need some conversion (this topic may help). Then you can do some zero padding with [combine]. Sorry, I don't have Max at hand and can't send you an example.
• Oct 30 2019 | 2:01 am
i might have done that somewhere but i am not sure.
• Oct 30 2019 | 2:12 am
hm, made a new one (only 2 attempts :) ) #P window setfont "Sans Serif" 9.; #P window linecount 1; #P newex 90 214 57 9109513 tosymbol; #P newex 496 101 57 9109513 tosymbol; #P newex 438 101 57 9109513 tosymbol; #P newex 380 101 57 9109513 tosymbol; #P newex 322 101 57 9109513 tosymbol; #P newex 264 101 57 9109513 tosymbol; #P newex 206 101 57 9109513 tosymbol; #P newex 148 101 57 9109513 tosymbol; #P newex 90 101 57 9109513 tosymbol; #P newex 90 314 50 9109513 print; #P newex 90 241 253 9109513 sprintf %s%s%s%s%s%s%s%s; #P toggle 496 60 27 0; #P toggle 438 60 27 0; #P toggle 380 60 27 0; #P toggle 322 60 27 0; #P toggle 264 60 27 0; #P toggle 206 60 27 0; #P toggle 148 60 27 0; #P newex 90 186 419 9109513 pak z z z z z z z z; #P toggle 90 60 27 0; #P connect 19 0 9 0; #P connect 1 0 19 0; #P connect 18 0 1 7; #P connect 17 0 1 6; #P connect 16 0 1 5; #P connect 15 0 1 4; #P connect 14 0 1 3; #P connect 13 0 1 2; #P connect 12 0 1 1; #P connect 8 0 18 0; #P connect 7 0 17 0; #P connect 6 0 16 0; #P connect 5 0 15 0; #P connect 4 0 14 0; #P connect 3 0 13 0; #P connect 2 0 12 0; #P connect 11 0 1 0; #P connect 0 0 11 0; #P connect 9 0 10 0; #P window clipboard copycount 20;
• Oct 30 2019 | 2:36 am
...and without spaces... not too elegant but works. #P window setfont "Sans Serif" 9.; #P window linecount 1; #P newex 106 318 67 9109513 itoa; #P newex 49 286 67 9109513 zl slice 1; #P newex 49 256 67 9109513 atoi; #P newex 49 214 253 9109513 sprintf _%s%s%s%s%s%s%s%s; #P newex 529 69 57 9109513 0; #P newex 529 37 57 9109513 loadbang; #P newex 455 136 57 9109513 tosymbol; #P newex 397 136 57 9109513 tosymbol; #P newex 339 136 57 9109513 tosymbol; #P newex 281 136 57 9109513 tosymbol; #P newex 223 136 57 9109513 tosymbol; #P newex 165 136 57 9109513 tosymbol; #P newex 107 136 57 9109513 tosymbol; #P newex 49 136 57 9109513 tosymbol; #P newex 106 389 50 9109513 print; #P toggle 455 89 27 0; #P toggle 397 89 27 0; #P toggle 339 89 27 0; #P toggle 281 89 27 0; #P toggle 223 89 27 0; #P toggle 165 89 27 0; #P toggle 107 89 27 0; #P newex 49 175 419 9109513 pak z z z z z z z z; #P toggle 49 89 27 0; #P connect 19 0 0 0; #P connect 0 0 10 0; #P connect 10 0 1 0; #P connect 1 0 20 0; #P connect 20 0 21 0; #P connect 21 0 22 0; #P connect 22 1 23 0; #P connect 23 0 9 0; #P connect 19 0 2 0; #P connect 2 0 11 0; #P connect 11 0 1 1; #P connect 19 0 3 0; #P connect 3 0 12 0; #P connect 12 0 1 2; #P connect 19 0 4 0; #P connect 4 0 13 0; #P connect 13 0 1 3; #P connect 19 0 5 0; #P connect 5 0 14 0; #P connect 14 0 1 4; #P connect 19 0 6 0; #P connect 6 0 15 0; #P connect 15 0 1 5; #P connect 19 0 7 0; #P connect 7 0 16 0; #P connect 16 0 1 6; #P connect 19 0 8 0; #P connect 8 0 17 0; #P connect 17 0 1 7; #P connect 18 0 19 0; #P window clipboard copycount 24;
• Oct 30 2019 | 3:00 am
@patrick
• Oct 30 2019 | 7:30 am
@roman I know I know, but I didn't like the idea of having 2 ^ -1 for 0 as input AND I wanted to keep some "bitwise operations" as asked in this thread's subject.
By the way, with modern systems you can go up to 62 without trouble ;-) (but I still enjoy- using Max4 and Max5 too !)
• Oct 30 2019 | 7:45 am
@leaozinho :
• Oct 30 2019 | 12:59 pm
i was about to ask: so it happens with 63 @ 64, too. :)
• Oct 30 2019 | 2:18 pm
Yes Roman, it does happen. I'm afraid there will be need for 128bits processors very soon! And Max16.