kvarnerexpress
Mar 1 2005, 12:40 AM
| | I'm working on a bitwise problem where I can't use loops or logical operators. I need to return 1 ix x<y else return 0. The valid operators that I can use are ! ~ & ^ | + << >>
My code that isn't working so far is: /* isLess - if x < y then return 1, else return 0 * Example: isLess(4,5) = 1. * Legal ops: ! ~ & ^ | + << >> * Max ops: 24
*/ int isLess(int x, int y) {
return ((x + (~y + 1)) >> 31 ) ; }
It seems to have problems with the negative numbers.
Going insane! |
Reply
osknockout
Mar 7 2005, 01:38 AM
Wow, I miss the C++ forums for some weeks, and see the changes! Alright, let's see. By ops you mean operations as in statement; not uops right? (assembly stuff) 'Cause otherwise it's crazy. I'm assuming you're talking about 2's complement negatives from your code . It seems your problem is that your code does NOT account for negative numbers. Example: int x = 4; int y = -5 return ((x + (~y + 1)) >> 31 ) ; /*Dev-C++ defines int in the range of -32768 to +32767, therefore : */ -> return ((4 + (~5 + 1)) >> 31; -> return (4 + -5) >> 31; -> return -1 >> 31; -> return 1; so 4 is less than -5  that's ok, I do the same thing at times. I'll get the answer to you when I think of it.
Reply
ssv
Mar 28 2005, 10:21 AM
I am new to this forum. I was hanging around this c,c++ section for a while and found this question pretty interesting. i have a code sample which i feel can do what is expected.bugs and comments are welcome int fun1(int num1 ,int num2) { int temp1 ,temp2; //if(num1 < num2) //return 1 //else //return 0 if(num1 >> 31) { if(!(num2 >> 31)) return 1; temp1 = ~(num1 + 0xFFFFFF); temp2 = ~(num2 + 0xFFFFFF); if((~temp2) & temp1) return 1; else return 0; } if((~num1) & num2) return 1; else return 0; } hope this code work for all possible values bye ssv
Reply
osknockout
Mar 28 2005, 06:06 PM
Hello ssv, I tested your sample on Dev-C++ (since I was too lazy to study it) using a range of 0 to 512 and using x and x-1 as parameters of your function. Here's what it returned: num1 num2 fun1() 0 -1 1 //ok, good so far 1 0 0 // 2 1 1 3 2 0 4 3 1 5 4 0 6 5 1 //ok, I get the picture now... ad 512... hmm... seems like a odd/even test. Sorry. It looks like you went great depths trying this one. Good try though. By the way, I haven't found a solution myself. Remember, kvarnerexpress stated that we can't use logical operators, so the if's and else's have to go if you want to declare it a solution. Here's my test code: CODE //uses iostream and fstream int main() { std::ofstream file("testfile"); int x = 0; while (x!=512) { file << fun1(x,x-1) << "\n"; x++; } return 0; }
Reply
Recent Queries:--
/* isless - if x < y then return 1, else return 0 * example: isless(4,5) = 1. * legal ops: ! ~ & ^ | << >> * max ops: 24 */ - 608.17 hr back. (1)
-
bitwise operators isless - 748.56 hr back. (1)
-
isless bitwise problem - 751.26 hr back. (1)
Similar Topics
Keywords : bitwise, problem
- Billing Problem. Plz Help
(2)
Problem With My Pc
crashes very frequently (2) My home PC has got a very seious problem....i took it about half a year ago..and in these six months
it has come up with more problems than my 6 year old PC.... It crashes very frequently...i have
tried good antivirus programs and i maintain it well too ...actually i have stopped doing it now
because every week during start up, a black screen shows up and the OS fails to load.... I then
reinstall XP and then again hope that it survives for another week... i am fed up of ths
reinstallations as it consumes the whole day....... The problem is..I still don't know what ....
Problem Concerning Credits Reduced
Reduced when I created a hosting account (12) My free web hosting account request for the second package was approved, which means that at the
time of the request (the topic itself) or the topic, however you want to name it, i had something
over 37 credits, positive and green of course, and when the admin actually approved the request, and
we all know that exactly when we see some changes on the request topic title, for instance, the
addiction of the words: "denied", "approved", et cetera. The point is that when the admin approved
today i had about 45 or 47 credits, and i created then the hosting account that only....
Problem With Hosting
delete it or wait it out? (4) Okay all I need help and or advice of this problem or delema. I have already posted that I have a
problem with logging into my cpanel, and have had replys of what to do, none worked. I have left a
ticket with xisto and no reply. Right now I am about to go Nuke over this. as some of you know my
site is a weather site and we have 2 systems on the east coast of the us. My problem is should I
wait this out and let the credits I have be used. "cant even access my own site" or save them and
just resign up and hope that takes care of the problem. Or even worse leave trap17 a....
What Is My (power) Problem?
(4) Hey all: I have a problem with my desktop. I have replaced the PSU a few times but now have a new
problem. When I turn on the power the green led on the asus motherboard glows green, but it is a
dull green and I cannot power up the machine. After some time (30-60 secs or more) it turns bright
green and I can power up. Then sometimes I am in the middle of working and the power will just
reset. When the computer boots up it starts loading the drivers then reboots again and keeps doing
this so it keeps rebooting and rebooting and rebooting and rebooting and rebooting ....
Attachment Problem In Pmwiki
The photos uploaded in PmWiki do not show themselves in the pages (0) Hi, I recently added PmWiki to my website. It is a great software, both light-weight and useful
with a lot of extensions. But a thorn is still in my side which is the attachments problem. When I
upload photos in a page the attachment just shows up like a text link which points to the uploaded
image without any image display. So I got stuck where I decided to make some profile pages for my
club members. Anybody here knows what to do? I have a little experience with PmWiki but I suggest
it to you if you do not want to be over killed by a system like what Wikipedia use....
Problem With The Trap17 Forum
Inconsistent links and problems with "Latest Activity" (4) Hi, I have noticed a bit of a problem with the forums here on Trap17. I don't know if this is a
problem with the Trap17 implementation, or with Invision Power Board in general, or with a mod that
is running on the forums here, and I'm sure that someone smarter than me can isolate the source
of the problem. What I have noticed firstly is that the link that is generated in the top right
corner of a post within a thread, the link to that particular post (I'll call that the linkback
link), sometimes links to the post itself, but often just links to the thread. T....
Counter Strike Problem
steam validation (2) Heloo i get a probelm steam validation rejected does anyone know how to fix it ?? i tried everything
im going to contact steam support to see if they can fix but can you guys help me?....
Hosting Credits Problem? [resolved]
(9) Hi. Last night I had HOSTING CREDITS : 29.67 DAYS credits. Now I have HOSTING CREDITS : 7.06 DAYS.
How on earth did they get reduced that quickly? I am so confused. Any help please?....
Firefox 3 Cookies Problem
It is reeeeeeally annoying (4) Hello The person who finds a solution for my problem would really be a life saver for me. I've
tried searching all over the web. Whenever I try to visit phpbb2 forums, I have to clean my cookies
before logging in, and this sux. I also get yahoo and google bad request errors. Here is the google
bad request: CODE Google Error Bad
Request Your client has issued a malformed or illegal request. Please see Google's
Terms of Service posted at http://www.google.com/terms_of_service.html ....
Problem With My Girlfriend Family, Need Suggestions For Action
Problem with my girlfriend family, need suggestions for action (2) It's been nearly 3 months that I am in abroad for my future study. Many things happened
/ohmy.gif" style="vertical-align:middle" emoid=":o" border="0" alt="ohmy.gif" /> in these 3 months
back in my home country. I had a girl friend /biggrin.gif" style="vertical-align:middle"
emoid=":D" border="0" alt="biggrin.gif" /> and both of our parents know that we are seeing and
dating each other and want to tie knot /tongue.gif" style="vertical-align:middle" emoid=":P"
border="0" alt="tongue.gif" /> in near future. We desperately love each other. Everything is going ....
Terminating Hosting Problem
(1) Well, a few days ago I terminated my hosting using the Credit System 2.0, but it still has me in the
group on the forums, which is making my credits go down for nothing. I need this fixed please.....
Browser Compatibility Problem With Firefox - Javascript + Css
Having trouble making a script work right - any suggestions? (3) Hi, Im working on a website, and im trying to make a right-click menu, which opens on right click,
wherever the cursor is, and closes on mouse out. I wrote the code below, and when i ran it in IE it
ran fine, just how i wanted it to work. However in firefox, the menu just opened in the top left. im
presuming this is because it doesnt like my style changing in the javascript. Any ideas, and
suggestions? If i cant make this work, i will just make it so it works slightly differently when
viewev in firefox so that it can just open in one place. All ideas appreciated. ....
Domain Problem : This Is Important..
(0) Hello all, This is important post, so please reply to it, i need the solution ans please don't
mind my english. Afternic don't care about their own rules /mad.gif"
style="vertical-align:middle" emoid=":angry:" border="0" alt="mad.gif" /> As some of you has
already read in the afternic area, My friend have an issue with a domain bought through
Afternic/NameMedia http://www.dnforum.com/f218/bought-d...ad-314697.html To be short, my friend
bought a domain for $2500, and paid immediately. The owner contacted him saying that it was
priced wrong (?) and t....
A Problem With Ftp Clients
I can't connect (9) I keep getting the message: "The requested name is valid and was found in the database, but it does
not have the correct associated data being resolved for", after following tutorial instructions for
Core FTP. If I try FileZilla, I never get automatically configured option in my sites section after
following the istruction Resolved ....
Youtube People That Do Not Respect Other Opinions
...This problem on YouTube (7) Very, very annoying. I am happy YouTube user - I probably spend some hours there every week. I
mostly look and listen to music but I also watch different shows. I always try to comment on
videos, if I like the videos or not. So many users seem to have a motto that says "Don't like,
don't watch." Well I have to watch it to know if I like it or not, right?! And that is not
even the worst part. It is almost like some people think you should only comment if you like it, and
if you have something else to say about it then you should glue your fingers together wi....
How Many More Times Will I Have To Post About This?
Problem just keeps lingering (11) I am wondering how many more times I will have to post about a problem that has been going on for
far too long now. I know it might not help nagging about it here, but I have submitted tickets,
which do not even get answered, while the problem happily lingers on. To be quite honest, I am
really getting enough of it now. What are Xisto/Trap 17 up to? Ever since the server migration,
there have been nothing but problems, and what is more, I am beginning to get the impression the
powers that be could not care less, as they do not reply to your tickets, and the problems do ....
Pop-up Virus / Trojan Problem
Constant pop-up, won't go away (10) Hi Guys, Lately I have had this same annoying pop-up dialog box pop up that says: QUOTE NOTICE:
If your computer has been running slower than normal, it may be infected with Viruses, Adware, or
Spyware. Adwareremover2007 will perform a quick and completely FREE scan of your system for
malicious programs. Download AdwareRemover2007 for FREE now! I have scanned it with Avira
AntiVirus and ad-aware2007. They both returned infected files, which i deleted, but i still have the
pop-ups. Any ideas?....
Sharing Files And Printer Between Windows Vista And Xp
Networking Problem (9) I have set up a wireless network between my two computers one vista and one XP I can access the
shared files from the vista machine on the XP PC but I cannot access the shared files or printer
which are on the XP PC via the vista one I don' think it is a firewall issue. Can anyone help
please it is driving me mad?? /biggrin.gif" style="vertical-align:middle" emoid=":D" border="0"
alt="biggrin.gif" />....
Dandruff Problem
(29) I am a average built, Indian, Male, aged 20 person. I have a very serious problem with the
dandruff. It comes back within an hour after taking a head bath. It is bothering me a lot. It is
very itching and really irritating. I have tried applying lemon on my head but in vain. The dandruff
still comes back. My mom advised me not to apply lemon too much on head so I have stopped applying
that also on head. I went to a doctor and he asked me to shampoo hair with a medicated shampoo
called SELSUN. But still the dandruff problem is lasting and with no effect with the medic....
Skype / Xampp Port Conflict
How to overcome the problem (5) XAMPP is a software package which installs a copy of the Apache Server, Mysql, PHP and Perl onto a
Windows computer and allows for local development of PHP and Mysql scripts without the need for
uploading onto your Hosting account to test for errors, etc. A really simple to install set of
softwares for those who need it. The manual install of all of these softwares can be difficult, but
the Installer supplied by XAMPP reduces the difficulty factor down to a single download and
essentially a one-click install. SKYPE is a software which allows using the Internet to make p....
Laptop Keyboard Problem
Dell Inspiron 6000 (8) First post on here and here it goes.... I got a laptop the "A" button now doesn't work. I pryed
off the black top to check if any dirt or liquid is under there and cleaned it put it back on and it
still doesn't work. I ordered a keyboard for my laptop off ebay. Now how exactly do i take off
the old one and put a new one in? Thanks....
Remote Assistance Problem
Won't work (9) I have tried tons of times and i can not get it too work. I did't even know about this until
Paul from Trap 17 used it to help me with something on my site. Whenever i try it, it never
connects. I have tried all three ways. Email, MSN, and download the file and send it. Both computers
are connected to the internet. On microsoft's site they have a lot of people with the same
problem, but no one ever helps with it. They are all unanswered. Paul: If you read this i know you
know how to do it.....
Php Header Problem
i always got header problem (11) i really hate the header function it always get an error saying ( cannot ------- headers already
sent by----- ) and here's my error: Warning: session_start(): Cannot send session cookie -
headers already sent by (output started at /home/adly3000/public_html/Mail/index.php:5) in
/home/adly3000/public_html/Mail/index.php on line 81 Warning: session_start(): Cannot send session
cache limiter - headers already sent (output started at /home/adly3000/public_html/Mail/index.php:5)
in /home/adly3000/public_html/Mail/index.php on line 81 Warning: Cannot modify header ....
Problem With Page Redirect
Help me out with this problem... (8) hey ppl, i just wanted a little help...i designed this website, but i want that if i click on
certain link, it should open new page for few seconds and then browser should automatically redirect
me to some other page....i tried this with header() function but i couldnt do the wait n redirect
part, ... so somebody plz help.... -thanx in advance! Thanks Avalon, topic changed. ....
Upload Component - Failed
Problem with Mambo (6) Hello! When I am trying to upload a component in joomla (I upgraded from mambo, I had the same
problem on mambo), it dont work, i get this error message: ! Upload component - Failed" "File
/home/esector/public_html/Gamesector/media/install_4381d76108f20/com_forum.zip does not exist!
" How can I fix it?....
I Have A Girl Problem Here
I like this girl and she likes me (27) Ok I have a girl problem here. I like this girl and she likes me back but there is a small problem.
She already has a boyfriend. I want to go ask her out but as you see she has a boyfriend. So my
question is what should I do. We are good friends and know each other pretty well.....
Problem Installing Sims 2 Nightlife
update failure (26) I have the Sims 2. I tried to install Sims 2 Nightlife expansionpack. He reches 100 % with
installing the game...then he automatically run the updat for the sims 2. But when he's going
trough the files he stops st the file: CSBin/package.exe He says there is a error, and then when I
click ok, install terminates and goes back from 100% to 0%. Can anybody tell me what's going
wrong here? Has anyone else had this problem? I just can't figure it out. And on the internet I
found a few people who had the same problem but just havent had an solution for it yet. Ca....
60 Seconds Countdown That Shutdown The Pc
Problem in computer that automatically restart COMPUTER (15) I encountered this bugs or what 6 months ago, untill now still gives me a headache. I don't
know if it is a virus, problem in windows services or what but honestly I cant fix it. What it does
is, it's gives you an error message saying blahh blahh...with a timer of 60 seconds, when the
timer reached 0 it will automatically restart your computer.....
Did You Face Problem Opening Pdf With Firefox?
(15) Hello, I have a question to ask since the 1st day of my download of firefox ... Whenever i open a
pdf file online using firefox, the firefox is get not responding and my comp got hanged ... i have
to manually end the firefox program via windows task manager .. I tried to wait the pdf to load, but
it seems that it takes forever .. so im guessing it's the trail version's bug .. but after a
few updates, I still have the problems with my firefox ... Is this my computer's problem or
firefox problem ? If it's a firefox bug, it's impossible that no1 report ....
Looking for bitwise, problem
|
*RANDOM STUFF*
*SIMILAR VIDEOS*
Searching Video's for bitwise, problem
*MORE FROM TRAP17.COM*
|
advertisement
|
|