Mapping an array to a decimal number from a binary number

when someone posts something like a vague and silly question (e.g., 'why?') resulted in a vague and silly answer. If you don't like it, tough. You can always toddle off to another thread.

It was me that posted that question. It was neither vague or silly. It was short and to the point. You had not explained why you wanted a solution in 20 or less lines but now we know.

I wanted it less than 20 lines, because I saw that the 20-line solution I had was sloppy and easily improved. But I didn't know how to improve it, so I asked here.

I also commented that it was 500 lines with the hope you'd think about it and consider that I didn't want to have to go through that many lines of code if there turned out to be some kind of math or parity issue.

It seems to me that my suggestion of using a function is the perfect answer to your question, whether or not the function has more or less than 20 lines.

You can test the function in isolation from your 500 other lines of code and when you are sure that it works incorporate it into your main program. Put it near the end of the source code or on a separate tab and you never have to see it again if you don't want to. Give the function and its arguments meaningful names and it becomes practically self documenting.

If you later suspect problems with that area of functionality then you can put debug statements in the function without the need to amend code anywhere else in the program. Furthermore, if you later want to try a different way of doing things you can rename or comment out the function and add another one with the original name without losing the original.