|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: |
bool singleton(int value) {
//Check if value = 0
if (value == 0) return false;
//This just implements the trick given in project description
int compare = value-1;
bool truth = value & compare;
if (truth == 0)
return true;
else
return false;
}
value = t1;
compare = t2;
t3 = value - 1;
singleton:
beq $t1, $0, end
sub $t3, $t1, 1
lw $t2, $t3
and $t4, $t1, $t2 //Truth statement
bne $t4, $0, end
lw $t5, 1 //True
end:
lw $t5, 0 //False
**********************************************************************************************************
int get_singleton(int value) {
int position = 0;
bool found = false;
// There's only one set bit so we continue shifting right until we find it.
// We find it by shifting right and ANDing with 1 where 1 is 0x01.
// Every time it's not found we increment position.
while(!found){
found = 1 & value;
value = value >> 1;
position++;
}
return position;
}
position = t1;
found = t2;
value = s1;
get_singleton:
lw $t1, $0
lw $t2, $0
loop:
and $t3, $t1, $s1
srl $s1, $s1, 1
addi $t1, $t1, 1
bne $t2, $0, loop
jr $ra
|
Advertisement
| Hall of Fame |