flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Main > Check if number fits 16 bits (signed or unsigned)

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 489
Location: Belarus

Check if number fits 16 bits (signed or unsigned)

How can I optimize the following line (for fasmg):

Code:

if (num > 0 & num < 65536) | (num < 32768 & num >= -32768)




P.S. not knowing num bit length (num can be 32 or 64 or whatever number of bits)
Post 19 Dec 2017, 21:02
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6772
Location: Kraków, Poland

These are two overlapping intervals. The "or" condition is like an union of these intervals, so this is equivalent to:

Code:
if num < 65536 & num >= -32768

Post 19 Dec 2017, 21:16
View user's profile Send private message Visit poster's website Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 489
Location: Belarus

Indeed, it's so obvious. I just overthought it too much. Thanks
Post 19 Dec 2017, 21:37
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.