From 0b3ebd841f498a73fef0c7ed9de731b0d69d3bb4 Mon Sep 17 00:00:00 2001 From: Wu Mianzhi <10215501411@stu.ecnu.edu.cn> Date: Sat, 17 Sep 2022 12:55:18 +0800 Subject: [PATCH] fix quiz7 --- lab2/datalab-handout/bits.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lab2/datalab-handout/bits.c b/lab2/datalab-handout/bits.c index 84e6363..48d604c 100644 --- a/lab2/datalab-handout/bits.c +++ b/lab2/datalab-handout/bits.c @@ -252,13 +252,14 @@ int conditional(int x, int y, int z) { int isLessOrEqual(int x, int y) { int signx = x >> 31; int signy = y >> 31; - int isnegpos = (signx ^ signy) & (~signx); // 0xFFFFF if signx = 1 sign y = 0 + int isnegpos = (signx ^ signy) & (signx); // 0xFFFFF if signx = 1 sign y = 0 + int isposneg = (signx ^ signy) & (signy); int sign1 = ~(1 << 31); // 01111111...111 int absx = x & sign1; int absy = y & sign1; int diff = absy + (~absx) + 1; int signdiff = diff >> 31; - int res = !isnegpos & !signdiff; + int res = !!isnegpos | (!isnegpos & !signdiff & !isposneg); return res; } //4