matrix - circular byte shifting in an array -


i'm coding led display (7x48) , language i'm working in basic (no former experience in language, in c/c++) , have small issue. have array (red[20] of byte) , example of current state is: make easier here lets red[3]

10011010 01011100 01011101

and need shift array 1 in next cycle supposed be

00110100 10111000 10111011

so happened whole array shifted 1 bit left

the basic i'm working doesn't have .net apis need total low level code (doesn't have basic, can translate it, need idea how i'm limited 8kb code memory have optmize it)

you should able use bit shift operations: http://msdn.microsoft.com/en-us/library/2d9yb87a.aspx

let x element want shift:

x = (x<<1) | (x>>23) 

or in general, if want shift left y bits , there total of n bits:

x = (x<<y) | (x>>(n-y)) 

i don't know basic well, here's in c++/java/c# language:

assuming have red[] of length n:

int b = 32; //number of bits per byte (your example showed 24, there 32) int y = 1; //number of bytes shift left int carry = 0;  //the bytes carry on (i'm assuming move array red[0] red[1], etc.  (int i=0;i<n;i++) {     int newcarry = (red[i]>>(n-y));     red[i] = (red[i]<<y) | carry;     carry = newcarry; }  //complete loop red[0]|=carry; 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -