sorry, stuck with the shifting counter, non-shifting is quicker, believe it or not
[/B][/QUOTE]Code:unsigned int reverseBits(unsigned int x) {
unsigned int res(0), cntr(32);
while (cntr--) {
res <<= 1;
res |= x & 1;
x >>= 1;
}
return res;
}
Printable View
sorry, stuck with the shifting counter, non-shifting is quicker, believe it or not
[/B][/QUOTE]Code:unsigned int reverseBits(unsigned int x) {
unsigned int res(0), cntr(32);
while (cntr--) {
res <<= 1;
res |= x & 1;
x >>= 1;
}
return res;
}
Nice job, techno.
Heh, that makes me think of one.. Come up with bitwise-shift and increment (or decrement) functions, using only the bitwise operations. (that doesn't include >> :))Quote:
sorry, stuck with the shifting counter, non-shifting is quicker, believe it or not
Why's everyone always got to spell my name wrong? :( Oh, right maybe cause I spelled it wrong in the first place. :DQuote:
Originally posted by Sepero
Nice job, techno.
I get that all the time as well, teckno:) I've had oozi, OOzi, Oozi, oozy...
Let's get it right people, it's an o, then a zero, then a z, then an i. But Rob will do fine:)
can it include << ? So you're looking for a counter?Quote:
Originally posted by Strogian
Heh, that makes me think of one.. Come up with bitwise-shift and increment (or decrement) functions, using only the bitwise operations. (that doesn't include >> :))
so we can use ~ ^ & | and what not, but no >>.
Just making sure I have this correct. I'll be spending the next 4 hours running long tests which need barely to no interaction. This'll give me something to do.
Well, I want functions that replace the ++ and >> operations, so naturally you shouldn't use ++ or >> in the function. :) (<< and -- are also no-good, but I don't think they'd help you anyway :))
Do you want replacments for both pre and post increments? (ie ++x and x++)
Oh, wow. I'd never thought of that. Hey, if you can do it, go ahead! :)
Looks like you have had some interesting theoretical/mathematical challenges, so far. Heres something practical:
Define a simple hangman program
It takes one word as its only parameter
The user has 2x as many guesses as there are letters in the word to guess the word. the user enters a letter on stdin, the program prints out the word, with that guess and any previous ones revealed as letters in the word, other letter are replaced by *. Also printed out is the number of guesses left before the user runs out of time. So a sample run may go as follows:
hangman sameple
e
***e**e
you have 13 guesses remaining
s
s**e**e
etc.
have fun, this is easy compared to some earlier challenges and will hopefully less able programmers a chance to test their skills.
mullet
I deciphered Sepero's first code. I mostly figured it out without a program but used it just to help. Anyway, I have attached the code to decipher the code in Perl. Did anyone else get it?
The python rot13 can be made way shorter:
:)Code:def rot13(s):
return s.encode('rot13')
I actually mention that in the original post... :pQuote:
Originally posted by Strike
The python rot13 can be made way shorter:
:)Code:def rot13(s):
return s.encode('rot13')
Heres a java solution for the add 2 numbers without +
Sorry for no indent, I did this in galeonCode:
public int add(int a, int b){
BigInteger bigA = new BigInteger(a);
BigInteger bigB = new BigInteger(b);
BigInteger ans = bigA.add(bigB);
return ans.intValue();
}
Design a binary code and write an encoder and decoder such that if as many as 3 bits of a codeword are encoded with errors, the decoder can correct the codeword. Obviously the only purpose of the encoder here is to take a codeword and mess it up in no more than three places. Your word length can be whatever you want, but the number of codewords needs to be at least 4. The shorter the word length and greater the number of codewords, the smarter your code is of course :).