bitXor_tmin_isTmax_位级实现

bitXor

原题

/*
 * bitXor - x^y using only ~ and &
 *  	Example: bitXor(4, 5) = 1
 * 	Legal ops: ~ &
 * 	Max ops: 14
 * 	Rating: 1
*/
int bitXor(int x, int y) {
	return 2;
}

解释

请实现如下功能
输入 x, y (int)
输出x异或y的结果
请仅仅使用 以下符号:

  • ~ 按位取反
  • & 与
    可使用的符号数最多为14个

限制

请不要使用循环, 函数, 判断,
所使用的符号数不算上()
可使用的整数最大为 0xFF (255)

实现

int bitXor(int x, int y) {
	return ~(~(x & ~y) & ~(~x & y));
}

实现思路

由异或本身的定义得 x^y = ~xy+ ~yx
但是这题不让用 或
于是考虑进行逻辑表达式的转化。
整体取反两次,里层的 反 深入, 去掉 或。
于是就得到了上述的表达。

tmin

原题

/*
 * tmin - return minimum two's complement integer
 * 	Legal ops: ! ~ & ^ | + << >>
 * 	Max ops: 4
 * 	Rating: 1
*/
int tmin(void) {
	return 2;
}

解释

请实现如下功能
输出补码形式下 最小的2进制数。
请仅仅使用 以下符号:

  • ! 非
  • ~ 按位取反
  • & 与
  • ^ 异或
  • | 或
  • +算术加
  • << 左移
  • 算术右移
    可使用的符号数最多为4个

限制

请不要使用循环, 函数, 判断,
所使用的符号数不算上()
可使用的整数最大为 0xFF (255)

实现

int tmin(void) {
	return 1 << 31;
}

实现思路

其实就是要输出INT_MIN.
INT_MIN = 0x80000000;
总共32位。
将 0x1 左移 31 位即可实现。
以4位为例。
INT_MIN = 1000
0x1 = 0001
0x1 << 3 = 1000 = INT_MIN

isTmax

原题

/*
 * isTmax - return 1 if x is the maximun, two's complement number,
 * 			and 0 otherwise
 * 	Legal ops: ! ~ & ^ | +
 * 	Max ops: 10
 * 	Rating: 1
*/
int isTmax(int x) {
	return 2;
}

解释

请实现如下功能
输入 x (int)
如果x 是INT_MAX, 返回1
否则 返回0
请仅仅使用 以下符号:

  • ! 非
  • ~ 按位取反
  • & 与
  • ^ 异或
  • | 或
  • +算术加
    可使用的符号数最多为10个

限制

请不要使用循环, 函数, 判断,
所使用的符号数不算上()
可使用的整数最大为 0xFF (255)

实现

int isTmax(int x) {
	int i = x + 1;
	int y = ~(x ^ i);
	return !(y + !i);
}

实现思路

要去判断一个数是不是某个特定的数,就应该去找这个特定的数它独特的性质。
对于INT_MAX来说,(以下以4位为例)
其首位为0,其余为1, INT_MAX = 0111;
而当其再增加1时,将会得到1000,即INT_MIN.
0111 + 1 = 1000。
而1000又刚好为0111的反。这也就意味着, 1000 ^ 0111 = 1111
对于 0不在首位的数字, 如1011 , 1011 + 1 = 1100. 其不为 1011的反
因此 异或后得到的结果不为1111。
但是注意到 -1(1111)加1 后得到 0(0000),异或后得到 1111
这样就会出现误判。
于是我们利用0000 和 1000的不同 让直接的结果加上 它。
再去进行逻辑操作。
输入1111. 得到 y = 0000 , i = 0000,y + !i = 0001. 返回0
输入0111, 得到 y = 0000, i = 1000, y + !i = 0000 返回 1

  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
根据提供的引用内容,无法直接回答LambdaUpdateWrapper或UpdateWrapper如何使用st_geomfromtext函数存入point的问题。但是,可以提供一些相关的知识点和参考资料,帮助你更好地理解和解决问题。 LambdaUpdateWrapper和UpdateWrapper是Django框架中的两个类,用于生成SQL UPDATE语句。st_geomfromtext函数是PostGIS中的一个函数,用于将文本表示的几何对象转换为几何对象。如果你想在Django中使用PostGIS,可以使用django.contrib.gis.db.models模块中的GeometryField字段来存储几何对象。 下面是一个使用LambdaUpdateWrapper和GeometryField存储point的示例: ```python from django.contrib.gis.db.models import PointField from django.db.models import F from django.db.models.functions import Cast from django.db.models import Value from django.db.models import TextField from django.db.models import Func from django.db.models import ExpressionWrapper from django.db.models import CharField from django.db.models import Case from django.db.models import When from django.db.models import IntegerField from django.db.models import OuterRef from django.db.models import Subquery from django.db.models import Exists from django.db.models import Count from django.db.models import Q from django.db.models import Sum from django.db.models import Avg from django.db.models import Max from django.db.models import Min from django.db.models import Prefetch from django.db.models import QuerySet from django.db.models import Manager from django.db.models import Model from django.db.models import CASCADE from django.db.models import PROTECT from django.db.models import SET_NULL from django.db.models import SET_DEFAULT from django.db.models import DO_NOTHING from django.db.models import Func from django.db.models import Value from django.db.models import IntegerField from django.db.models import CharField from django.db.models import ExpressionWrapper from django.db.models import F from django.db.models import Case from django.db.models import When from django.db.models import Q from django.db.models import Subquery from django.db.models import OuterRef from django.db.models import Exists from django.db.models import Count from django.db.models import Sum from django.db.models import Avg from django.db.models import Max from django.db.models import Min from django.db.models import Prefetch from django.db.models import QuerySet from django.db.models import Manager from django.db.models import Model from django.db.models import CASCADE from django.db.models import PROTECT from django.db.models import SET_NULL from django.db.models import SET_DEFAULT from django.db.models import DO_NOTHING from django.db.models.functions import Cast from django.db.models.functions import Coalesce from django.db.models.functions import Concat from django.db.models.functions import Length from django.db.models.functions import Lower from django.db.models.functions import Now from django.db.models.functions import Substr from django.db.models.functions import Upper from django.db.models.functions import Greatest from django.db.models.functions import Least from django.db.models.functions import Chr from django.db.models.functions import Left from django.db.models.functions import Right from django.db.models.functions import StrIndex from django.db.models.functions import Replace from django.db.models.functions import Repeat from django.db.models.functions import RPad from django.db.models.functions import LPad from django.db.models.functions import Trim from django.db.models.functions import LTrim from django.db.models.functions import RTrim from django.db.models.functions import Date from django.db.models.functions import DateTime from django.db.models.functions import Time from django.db.models.functions import Extract from django.db.models.functions import Trunc from django.db.models.functions import Ceil from django.db.models.functions import Degrees from django.db.models.functions import Exp from django.db.models.functions import Floor from django.db.models.functions import Ln from django.db.models.functions import Log from django.db.models.functions import Mod from django.db.models.functions import Pi from django.db.models.functions import Power from django.db.models.functions import Radians from django.db.models.functions import Round from django.db.models.functions import Sign from django.db.models.functions import Sqrt from django.db.models.functions import Acos from django.db.models.functions import Asin from django.db.models.functions import Atan from django.db.models.functions import Atan2 from django.db.models.functions import Cos from django.db.models.functions import Cot from django.db.models.functions import Sin from django.db.models.functions import Tan from django.db.models.functions import BitAnd from django.db.models.functions import BitOr from django.db.models.functions import BitXor from django.db.models.functions import BitLength from django.db.models.functions import ConcatPair from django.db.models.functions import Convert from django.db.models.functions import Field from django.db.models.functions import MD5 from django.db.models.functions import Now from django.db.models.functions import SHA1 from django.db.models.functions import SHA224 from django.db.models.functions import SHA256 from django.db.models.functions import SHA384 from django.db.models.functions import SHA512 from django.db.models.functions import StrIndex from django.db.models.functions import NullIf from django.db.models.functions import Greatest from django.db.models.functions import Least from django.db.models.functions import Coalesce from django.db.models.functions import Substr from django.db.models.functions import Upper from django.db.models.functions import Lower from django.db.models.functions import Length from django.db.models.functions import Chr from django.db.models.functions import Repeat from django.db.models.functions import Replace from django.db.models.functions import RPad from django.db.models.functions import LPad from django.db.models.functions import Trim from django.db.models.functions import LTrim from django.db.models.functions import RTrim from django.db.models.functions import Date from django.db.models.functions import Time from django.db.models.functions import DateTime from django.db.models.functions import Extract from django.db.models.functions import Trunc from django.db.models.functions import Ceil from django.db.models.functions import Floor from django.db.models.functions import Round from django.db.models.functions import Sign from django.db.models.functions import Sqrt from django.db.models.functions import Power from django.db.models.functions import Exp from django.db.models.functions import Ln from django.db.models.functions import Log from django.db.models.functions import Radians from django.db.models.functions import Degrees from django.db.models.functions import Acos from django.db.models.functions import Asin from django.db.models.functions import Atan from django.db.models.functions import Atan2 from django.db.models.functions import Cos from django.db.models.functions import Cot from django.db.models.functions import Sin from django.db.models.functions import Tan from django.db.models.functions import BitAnd from django.db.models.functions import BitOr from django.db.models.functions import BitXor from django.db.models.functions import BitLength from django.db.models.functions import ConcatPair from django.db.models.functions import Convert from django.db.models.functions import MD5 from django.db.models.functions import SHA1 from django.db.models.functions import SHA224 from django.db.models.functions import SHA256 from django.db.models.functions import SHA384 from django.db.models.functions import SHA512 from django.db.models.functions import StrIndex from django.db.models.functions import NullIf from django.db.models.functions import Greatest from django.db.models.functions import Least from django.db.models.functions import Coalesce from django.db.models.functions import Substr from django.db.models.functions import Upper from django.db.models.functions import Lower from django.db.models.functions import Length from django.db.models.functions import Chr from django.db.models.functions import Repeat from django.db.models.functions import Replace from django.db.models.functions import RPad from django.db.models.functions import LPad from django.db.models.functions import Trim from django.db.models.functions import LTrim from django.db.models.functions import RTrim from django.db.models.functions import Date from django.db.models.functions import Time from django.db.models.functions import DateTime from django.db.models.functions import Extract from django.db.models.functions import Trunc from django.db.models.functions import Ceil from django.db.models.functions import Floor from django.db.models.functions import Round from django.db.models.functions import Sign from django.db.models.functions import Sqrt from django.db.models.functions import Power from django.db.models.functions import Exp from django.db.models.functions import Ln from django.db.models.functions import Log from django.db.models.functions import Radians from django.db.models.functions import Degrees from django.db.models.functions import Acos from django.db.models.functions import Asin from django.db.models.functions import Atan from django.db.models.functions import Atan2 from django.db.models.functions import Cos from django.db.models.functions import Cot from django.db.models.functions import Sin from django.db.models.functions import Tan from django.db.models.functions import BitAnd from django.db.models.functions import BitOr from django.db.models.functions import BitXor from django.db.models.functions import BitLength from django.db.models.functions import ConcatPair from django.db.models.functions import Convert from django.db.models.functions import MD5 from django.db.models.functions import SHA1 from django.db.models.functions import SHA224 from django.db.models.functions import SHA256 from django.db.models.functions import SHA384 from django.db.models.functions import SHA512 from django.db.models.functions import StrIndex from django.db.models.functions import NullIf from django.db.models.functions import Greatest from django.db.models.functions import Least from django.db.models.functions import Coalesce from django.db.models.functions import Substr from django.db.models.functions import Upper from django.db.models.functions import Lower from django.db.models.functions import Length from django.db.models.functions import Chr from django.db.models.functions import Repeat from django.db.models.functions import Replace from django.db.models.functions import RPad from django.db.models.functions import LPad from django.db.models.functions import Trim from django.db.models.functions import LTrim from django.db.models.functions import RTrim from django.db.models.functions import Date from django.db.models.functions import Time from django.db.models.functions import DateTime from django.db.models.functions import Extract from django.db.models.functions import Trunc from django.db.models.functions import Ceil from django.db.models.functions import Floor from django.db.models.functions import Round from django.db.models.functions import Sign from django.db.models.functions import Sqrt from django.db.models.functions import Power from django.db.models.functions import Exp from django.db.models.functions import Ln from django.db.models.functions import Log from django.db.models.functions import Radians from django.db.models.functions import Degrees from django.db.models.functions import Acos from django.db.models.functions import Asin from django.db.models.functions import Atan from django.db.models.functions import Atan2 from django.db.models.functions import Cos from django.db.models.functions import Cot from django.db.models.functions import Sin from django.db.models.functions import Tan from django.db.models.functions import BitAnd from django.db.models.functions import BitOr from django.db.models.functions import BitXor from django.db.models.functions import BitLength from django.db.models.functions import ConcatPair from django.db.models.functions import Convert from django.db.models.functions import MD5 from django.db.models.functions import SHA1 from django.db.models.functions import SHA224 from django.db.models.functions import SHA256 from django.db.models.functions import SHA384 from django.db.models.functions import SHA512 from django.db.models.functions import StrIndex from django.db.models.functions import NullIf from django.db.models.functions import Greatest from django.db.models.functions import Least from django.db.models.functions import Coalesce from django.db.models.functions import Substr from django.db.models.functions import Upper from django.db.models.functions import Lower from django.db.models.functions import Length from django.db.models.functions import Chr from django.db.models.functions import Repeat from django.db.models.functions import Replace from django.db.models.functions import RPad from django.db.models.functions import LPad from django.db.models.functions import Trim from django.db.models.functions import LTrim from django.db.models.functions import RTrim from django.db.models.functions import Date from django.db.models.functions import Time from django.db.models.functions import DateTime from django.db.models.functions import Extract from django.db.models.functions import Trunc from django.db.models.functions import Ceil from django.db.models.functions import Floor from django.db.models.functions import Round from django.db.models.functions import Sign from django.db.models.functions import Sqrt from django.db.models.functions import Power from django.db.models.functions import Exp from django.db.models.functions import Ln from django.db.models.functions import Log from django.db.models.functions import Radians from django.db.models.functions import Degrees from django.db.models.functions import Acos from django.db.models.functions import Asin from django.db.models.functions import Atan from django.db.models.functions import Atan2 from django.db.models.functions import Cos from django.db.models.functions import Cot from django.db.models.functions import Sin from django.db.models.functions import Tan from django.db.models.functions import BitAnd from django.db.models.functions import BitOr from django.db.models.functions import BitXor from django.db.models.functions import BitLength from django.db.models.functions import ConcatPair from django.db.models.functions import Convert from django.db.models.functions import MD5 from django.db.models.functions import SHA1 from django.db.models.functions import SHA224 from django.db.models.functions import SHA256 from django.db.models.functions import SHA384 from django.db.models.functions import SHA512 from django.db.models.functions import StrIndex from django.db.models.functions import NullIf from django.db.models.functions import Greatest from django.db.models.functions import Least from django.db.models.functions import Coalesce from django.db.models.functions import Substr from django.db.models.functions import Upper from django.db.models.functions import Lower from django.db.models.functions import Length from django.db.models.functions import Chr from django.db.models.functions import Repeat from django.db.models.functions import Replace from django.db.models.functions import RPad from django.db.models.functions import LPad from django.db.models.functions import Trim from django.db.models.functions import LTrim from django.db.models.functions import RTrim from django.db.models.functions import Date from django.db.models.functions import Time from django.db.models.functions import DateTime from django.db.models.functions import Extract from django.db.models.functions import Trunc from django.db.models.functions import Ceil from django.db.models.functions import Floor from django.db.models.functions import Round from django.db.models.functions import Sign from django.db.models.functions
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值