Scientific Calculator
shiwei/Signed2unsigned
By ryan
//This function covert an signed integer number into an unsinged //integer number. list is the input vector while width means the //width of input number; //Example: a = [-2,-1,0,1]; //Signed2unsigned(a,2); THEN return [2,3,0,1]
Tagged:
var Signed2unsigned = function(list,width){
var sign = 0;
var tmp;
var i = 0;
while ( i < len list ) -> (
sign = list[i] < 0?1:0;
tmp = 2^width*sign;
list[i] = list[i] + tmp;
i += 1;
);
list;
}
0 Comments
Sign in to leave a comment