Scientific Calculator

(public) shiwei/Signed2unsigned

By shiwei 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: integer signed unsigned


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;

}

spam? | offensive?

0 Comments

Sign in to leave a comment