Qbasicnews.com

Full Version: Rotate left 2 bits (like assembler)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10
To all:

Unless Lithium submits a corrected solution, this ends this thread.

The winner is Z!RE for the most straightforward, 100% working solution.

Second place goes to MANGO for a clever, relatively simple solution, which works 100%.

Third place goes to BLITZ, who after several attempts submitted a 100% working solution, which I considered quite complicated.

Thanks to ShiftLynx and Lithium for their efforts and contributions which for one reason or another didn't perform 100%.

It's amazing how one line of code in assembly language creates such a variety of lengthy solutions in QB.

I think we all learned things on this "project". I know I did.
*****
Moneo, i hope that your announcment of the winner is a joke, if it's not then you definitly shouldn't be starting any more challenges. Becuase first of all you completly ignored all the other 4 entrants. Second, you do not seem to really understand the innerworkings of your own challenges. Third, you seem to start a challenge everytime you get stuck on something.

Here's your code in case that overflows. Obviously you have to run it in the ide to notice the overflow.

Code:
REM NOTE: X is the input 16 bit value to be rotated 2 left.
REM            X2 is the output 16 bit value as an integer.

DIM x AS LONG
DIM x2 AS INTEGER
DIM hexC000 AS LONG
DIM hex3FFF AS LONG
DIM top2 AS LONG
DIM bot2 AS LONG

x = 2 ^ 13

hexC000 = &HC000&           'Bit mask to isolate 2 high-order bits
hex3FFF = &H3FFF&           'Bit mask to remove  2 high-order bits

top2 = x AND hexC000        'Isolate 2 high-order bits
bot2 = top2 / 2 ^ 14        'Position 2 high-order bits into 2 low-order bits

x = x AND hex3FFF         'Remove 2 high-order bits from x (just in case)
x = x * 2 ^ 2             'Shift x left 2 bits
x = x OR bot2             'OR in the 2 low-order bits          

REM X is the final result as long.
x2 = x                       'x2 is the final 16 bit result as integer
Christ, you should retire from programming period.
All my solutions where the same one, and they all produced the same output. Except that you failed to recognise it. Coding in asm before i was born? It sure doesn't show.
Even though I won I have to agree with Blitz..

This whole challenge is just stupid..


You discard solutions when they are able to do anything beyond what you asked for.

Then you go and give me extra points for my code being easy, and that you only have to change one line to make it do other things.

When the other solutions, you only had to change a passed argument.


I reject the "prize".. I don't deserve it. Period.
i hope you are not employed as a programmer in a real life company. i guess i will send this little piece of fun to thedailywtf.com, so you finally get your honor. moneo what's wrong with you dude?
Code:
DIM SHARED shiftLeft%(255), shiftRight%(255)

FOR i% = 0 TO 255
shiftLeft%(i%) = (i% * 4) AND 255
shiftRight%(i%) = i% \ 64
NEXT i%

SUB rol2(a%)
DEF SEG = VARSEG(a%)
ptr% = VARPTR(a%)
l% = PEEK(ptr%)
h% = PEEK(ptr% + 1)
POKE ptr%, shiftLeft%(l%) OR shiftRight%(h%)
POKE ptr% + 1, shiftLeft%(h%) OR shiftRight%(l%)
END SUB
Code:
SUB ROL2 (a%)
DIM code&(3)
code&(0) = -1959337079: code&(1) = 126551135
code&(2) = -1059913039: code&(3) = 13305737
DEF SEG = VARSEG(code&(0))
CALL ABSOLUTE(a%, VARPTR(code&(0)))
END SUB
When I post a challenge:
- I try to be fair to all those submitting solutions.
- I may reject solutions because they don't conform to specs.
- If I get a clean compile for solutions, I test every one of them.
- I usually have to write test programs to embed the submitted solutions.
- I provide feedback regarding the performance of each solution.

Hardly any other challenge provides the above participation and support by the author of the challenge.

If some of you disagree with my final decisions and ranking of the submitted solutions, that's fine, do a poll and rank you're own winners.
*****
BLITZ,
I don't know why my solution gets an overflow when running in the IDE. I never use the IDE, and I don't have it; that is, I always compile. So, if my solution doesn't run in the IDE, then we can consider that it doesn't work, since the challenge stated using QB and didn't specifiy IDE or compiled.


LOGICLRD, the challenge had already been closed.

*****
I request you remove me as winner.
Pages: 1 2 3 4 5 6 7 8 9 10