Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Hello World!")
- ---------------------------------------
- function hasbit(x, p)
- return (x % (p + p) >= p)
- end
- local function BitXOR(a,b)--Bitwise xor
- local p,c=1,0
- while a>0 and b>0 do
- local ra,rb=a%2,b%2
- if ra~=rb then c=c+p end
- a,b,p=(a-ra)/2,(b-rb)/2,p*2
- end
- if a<b then a=b end
- while a>0 do
- local ra=a%2
- if ra>0 then c=c+p end
- a,p=(a-ra)/2,p*2
- end
- return c
- end
- local function BitOR(a,b)--Bitwise or
- local p,c=1,0
- while a+b>0 do
- local ra,rb=a%2,b%2
- if ra+rb>0 then c=c+p end
- a,b,p=(a-ra)/2,(b-rb)/2,p*2
- end
- return c
- end
- local function BitNOT(n)
- local p,c=1,0
- while n>0 do
- local r=n%2
- if r<1 then c=c+p end
- n,p=(n-r)/2,p*2
- end
- return c
- end
- local function BitAND(a,b)--Bitwise and
- local p,c=1,0
- while a>0 and b>0 do
- local ra,rb=a%2,b%2
- if ra+rb>1 then c=c+p end
- a,b,p=(a-ra)/2,(b-rb)/2,p*2
- end
- return c
- end
- function lshift(x, by)
- return x * 2 ^ by
- end
- function rshift(x, by)
- return math.floor(x / 2 ^ by)
- end
- ----------------------------------------------
- --[[
- int crc_init(void)
- {
- crc_deinit();
- pcrc_table = (unsigned int *)malloc(sizeof(int)*8*256);
- if(NULL == pcrc_table){
- printf("crc malloc error!\n");
- return 0;
- }
- int i, j;
- unsigned int c;
- for (i=0;i<256;i++)
- {
- for (c=i,j=0;j<8;j++)
- c = (c & 1) ? (c>>1)^0xEDB88320L : (c>>1);
- pcrc_table[i] = c;
- }
- return 1;
- }
- ]]
- for i=0, 255 do
- for j=0, 7 do
- c = i
- if (hasbit(c, 1)) then print (c) end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment