DEFINE
Year = New
Happy = Variable, Objective = True
END DEFINE
OK so here's a hypothetical problem for you thinkers....
Using any make of PLC, (or a PC program if that's your thing), and any programming language you choose, what is the shortest method (in terms of number of instructions) of non-destructively reversing the bit order in an 8-bit byte?
No prizes, but I'd be interested to see what you guys might come up with.
The simplest way is obviously 8 rungs of code that maps bit 0 to 7, 1 to 6 etc., but I'd be particularly impressed with a solution that didn't use any "intermediate" storage, which IS possible, but it involves some lateral thinking.
Not an original puzzle-problem, I came across it many years ago in a computing magazine. Some of the solutions given I didn't understand at the time..... maybe I won't this time around either...
The "lateral thinking" solution I mentioned above was certainly the outright winner in terms of code efficiency, but it was ruled out on the basis that it wasn't strictly handled in code, but the author received a special commendation for his thinking !
Year = New
Happy = Variable, Objective = True
END DEFINE
OK so here's a hypothetical problem for you thinkers....
Using any make of PLC, (or a PC program if that's your thing), and any programming language you choose, what is the shortest method (in terms of number of instructions) of non-destructively reversing the bit order in an 8-bit byte?
No prizes, but I'd be interested to see what you guys might come up with.
The simplest way is obviously 8 rungs of code that maps bit 0 to 7, 1 to 6 etc., but I'd be particularly impressed with a solution that didn't use any "intermediate" storage, which IS possible, but it involves some lateral thinking.
Not an original puzzle-problem, I came across it many years ago in a computing magazine. Some of the solutions given I didn't understand at the time..... maybe I won't this time around either...
The "lateral thinking" solution I mentioned above was certainly the outright winner in terms of code efficiency, but it was ruled out on the basis that it wasn't strictly handled in code, but the author received a special commendation for his thinking !