Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stretch mask - bit manipulation

I want to stretch a mask in which every bit represents 4 bits of stretched mask. I am looking for an elegant bit manipulation to stretch using c++ and systemC

for example:

input:

mask (32 bits) = 0x0000CF00

output:

stretched mask (128 bits) = 0x00000000 00000000 FF00FFFF 00000000

and just to clarify the example let's look at the the byte C:

0xC = 1100 after stretching: 1111111100000000 = 0xFF00
like image 545
Noa Yehezkel Avatar asked Dec 13 '25 21:12

Noa Yehezkel


1 Answers

Do this in a elegant form is not easy. The simple mode maybe is create a loop with shift bit

sc_biguint<128> result = 0;
for(int i = 0; i < 32; i++){
    if(bit_test(var, i)){
        result +=0x0F;
    }
    result << 4;
}
like image 113
rodrigo Avatar answered Dec 16 '25 16:12

rodrigo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!