drewcrew6
Member
Is there a clean way of taking an integer value of 0 to 15 and turning on the same bits?
if input value is 1 then bit 1 is on
if input value is 2 then bits 1+2 are on
if input value is 3 then bits 1,2 and 3 are on
""
""
""
if input value is 15 then all 15 bits are on
I've done it with a lookup table and also clearing the bits on change then using an add n7:0 + n7:0 + 1 = (bits to be on) for "input value" amount of times,starting with a 1 in n7:0.
They both seem sloppy for what I would like to do.
Thanks
Drewcrew6
if input value is 1 then bit 1 is on
if input value is 2 then bits 1+2 are on
if input value is 3 then bits 1,2 and 3 are on
""
""
""
if input value is 15 then all 15 bits are on
I've done it with a lookup table and also clearing the bits on change then using an add n7:0 + n7:0 + 1 = (bits to be on) for "input value" amount of times,starting with a 1 in n7:0.
They both seem sloppy for what I would like to do.
Thanks
Drewcrew6