flat assembler
Message board for the users of flat assembler.

Index > Main > Check if number fits 16 bits (signed or unsigned)

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 19 Dec 2017, 21:02
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



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 19 Dec 2017, 21:16
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: 501
Location: Belarus
zhak 19 Dec 2017, 21:37
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


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.