Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 11_isZero.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ int test_isZero(int x)
int main(void)
{
int x = 0;
printf("expected: %x\n", isZero(x));
printf("expected: %x\n", isZero(x^0));
printf("actual : %x\n", test_isZero(x));
}
2 changes: 1 addition & 1 deletion 12_minusOne.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
int minusOne(void)
{
return 2;
return ~0X0;
}

int test_minusOne(void)
Expand Down
Binary file added 13_tmin
Binary file not shown.
2 changes: 1 addition & 1 deletion 13_tmin.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
int tmin(void)
{
return 2;
return (1<<31);
}

int test_tmin(void)
Expand Down
Binary file added 14_tmax
Binary file not shown.
2 changes: 1 addition & 1 deletion 14_tmax.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
int tmax(void)
{
return 2;
return ~(1<<31);
}

int test_tmax(void)
Expand Down
Binary file added 15_isTmin
Binary file not shown.
2 changes: 1 addition & 1 deletion 15_isTmin.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
int isTmin(int x)
{
return 2;
return !(x^(1<<31));
}

int test_isTmin(int x)
Expand Down
Binary file added 16_isTmax
Binary file not shown.
2 changes: 1 addition & 1 deletion 16_isTmax.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
int isTmax(int x)
{
return 2;
return x&&~(1<<31);
}

int test_isTmax(int x)
Expand Down
Binary file added 21_bitMatch
Binary file not shown.
2 changes: 1 addition & 1 deletion 21_bitMatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
int bitMatch(int x, int y)
{
return 2;
return (x&y)|(~x&~y);
}

int test_bitMatch(int x, int y)
Expand Down
Binary file added 22_evenBits
Binary file not shown.
4 changes: 3 additions & 1 deletion 22_evenBits.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
*/
int evenBits(void)
{
return 2;
int x=0;
x=0x55<<8 | 0x55<<16 | 0x55<<24 | 0x55;
return x;
}

int test_evenBits(void)
Expand Down
Binary file added 23_thirdBits
Binary file not shown.
3 changes: 2 additions & 1 deletion 23_thirdBits.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
*/
int thirdBits(void)
{
return 2;
return 0x49<<9 | 0x49<<18 | 0x49<<27 | 0x49 ;
}


int test_thirdBits(void)
{
int result = 0;
Expand Down
Binary file added 24_upperBits
Binary file not shown.
10 changes: 5 additions & 5 deletions 24_upperBits.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
*/
int upperBits(int n)
{
return 2;
return (0x01<<31)>>n-1;
}

// 0000 0000
int test_upperBits(int x)
{
int result = 0;
Expand All @@ -24,7 +24,7 @@ int test_upperBits(int x)

int main(void)
{
int x = 32;
printf("expected: %x\n", upperBits(x));
printf("actual : %x\n", test_upperBits(x));
int x = 0;
printf("expected: %x\n", test_upperBits(x));
printf("actual : %x\n", upperBits(x));
}
Binary file added 25_fitsShort
Binary file not shown.
2 changes: 1 addition & 1 deletion 25_fitsShort.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
int fitsShort(int x)
{
return 2;
return x<<16;
}

int test_fitsShort(int x)
Expand Down
Binary file added 33_bitNor
Binary file not shown.
9 changes: 8 additions & 1 deletion 33_bitNor.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
/*
* bitNor - ~(x|y) using only ~ and &
* Example: bitNor(0x6, 0x5) = 0xFFFFFFF8
0110
0101
1000

1001
1010
1000
* Legal ops: ~ &
* Max ops: 8
* Rating: 1
*/
int bitNor(int x, int y)
{
return 2;
return (~x&~y);
}

int test_bitNor(int x, int y)
Expand Down
Binary file added 34_bitXor
Binary file not shown.
4 changes: 3 additions & 1 deletion 34_bitXor.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
* Max ops: 14
* Rating: 1
*/


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

int test_bitXor(int x, int y)
Expand Down
Binary file added out
Binary file not shown.