0

Left shift operaion and combining 3char to form an int value

Hi all,

I am trying to implement the following C functionality in scilab.

uint8_t Packet[3] = {0x01,0x02,0x03};

int32_t Val=(((Packet[l0]>0x7F)?0xff000000:0x00)|(Packet[0]<<16)|(Packet[l1]<<8)|Packet[2]);

But I don't know how to do this shift operation?

Your valuable comments are appreciated.

Thanks

Likhitha

Scilab

__Answers:__

0

There are no native bit shift / rotation operations in scilab. You may write a function for the same.

The following **bitshift** function is taken from https://x-engineer.org/graduate-engineering/embedded-systems/microcontrollers/bit-shift-rotation-algorithms-scilab/

function y=bitshift(str,dir,n,bit) dec=bin2dec(str); switch bit case 8 if dir=='r' then y=dec2bin(uint8(dec/(2^n)),bit); elseif dir=='l' then y=dec2bin(uint8(dec*(2^n)),bit); end case 16 if dir=='r' then y=dec2bin(uint16(dec/(2^n)),bit); elseif dir=='l' then y=dec2bin(uint16(dec*(2^n)),bit); end case 32 if dir=='r' then y=dec2bin(uint32(dec/(2^n)),bit); elseif dir=='l' then y=dec2bin(uint32(dec*(2^n)),bit); end case 64 if dir=='r' then y=dec2bin(uint64(dec/(2^n)),bit); elseif dir=='l' then y=dec2bin(uint64(dec*(2^n)),bit); end end endfunction

Login to add comment