xxxxxxxxxx
67
var dec=244; // Decimal number in
var hexA=[]; // HEx array
var hexn=""; // Hex Number
function setup() {
createCanvas(400, 400);
convert(dec);
console.log(hex(dec));
}
function draw() {
background(220);
}
function convert(num)
{
var remainder=num;
var quotient=0;
var n=num;
while(n)
{
quotient=floor(n/16)
remainder=n%16;
if(remainder<10)
{
hexA.push(str(remainder))
}
else
{
switch(remainder)
{
case 10: hexA.push("A");
break;
case 11: hexA.push("B");
break;
case 12: hexA.push("C");
break;
case 13: hexA.push("D");
break;
case 14: hexA.push("E");
break;
case 15: hexA.push("F");
break;
}
}
n=quotient;
}
for(var i=0; i<hexA.length; i++)
{
if(i==0)
{
if(hexA[i]!="0")
hexn=hexn+hexA[i];
}
else
{
hexn=hexn+hexA[i];
}
}
return hexn;
}