在C二进制,看看测试一个数是否在范围内 [英] In c binary, testing to see if a number is in range

查看:152
本文介绍了在C二进制,看看测试一个数是否在范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想不通谜题的一部分。该函数接受三个输入。第一个是int,第二个是下界,三是上限。我需要测试,看看是否能第一个数字是内部的下限和上限的包容性。

This is part of a puzzle that I can't figure out. The function takes in three inputs. The first is an int, the second is the lower bound and the third is the upper bound. I need to test to see if that first number is within the lower and upper bound inclusive.

如果它是在范围,则返回1,否则返回0。
美中不足的是,我只能用

If it is in range then return 1, else return 0. The catch is that I can only use

! ~ & ^ | + << >> 

操作,只有一个人20 ..的组合此外,只有诠释可以使用的变量,并没有如语句,循环或函数调用。

operations and only a combination of 20 of them.. Also, only int variables may be used, and no if statements, loops or function calls.

Range(int x, int lower, int upper){
//... some code here
return retVal;
}

显然,我了解这里的逻辑。如果((X> =低级)及及(X'LT =上部))返回1;
唯一的问题是,我无法使用if语句,&LT;,>,==,或放大器;&安培;

Obviously I understand the logic here. If((x >= lower) && (x <= upper)) return 1; The only problem is that I can't use if statements, <, >, ==, or &&.

推荐答案

我喜欢这些难题,你有!为此,您会希望有一些像,

I'm liking these puzzles you have! For this you will want to have something like,

确定要在这一个抽象的,你会想有2个变量。

Ok to be abstract on this one, you will want to have 2 variables.

第一个变量(可以称之为blarg),你需要设置上限,并添加翻转的X.
现在,您将要添加一个blarg和翻转。

The first variable (lets call it blarg) you need to set the upper bound and add the flipped x. Now you will want to add one to blarg and flip it.

您第二个变量(可以称之为持有)将在x添加到翻转下界;之后,加1,保持和翻动它。

Your second variable (lets call it hold) will add the x to the flipped lower bound; After that add 1 to hold and flip it too.

设置blarg =为blarg加持;
超过31移blarg的权利。
与1 AND吧。

set blarg = to the blarg plus hold; shift blarg over 31 to the the right. and AND it with 1.

应该是你在找什么。

这篇关于在C二进制,看看测试一个数是否在范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆