repeat83

Untitled

Jan 7th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. print("Hello World!")
  2.  
  3. ---------------------------------------
  4.  
  5. function hasbit(x, p)
  6. return (x % (p + p) >= p)
  7. end
  8.  
  9. local function BitXOR(a,b)--Bitwise xor
  10. local p,c=1,0
  11. while a>0 and b>0 do
  12. local ra,rb=a%2,b%2
  13. if ra~=rb then c=c+p end
  14. a,b,p=(a-ra)/2,(b-rb)/2,p*2
  15. end
  16. if a<b then a=b end
  17. while a>0 do
  18. local ra=a%2
  19. if ra>0 then c=c+p end
  20. a,p=(a-ra)/2,p*2
  21. end
  22. return c
  23. end
  24.  
  25. local function BitOR(a,b)--Bitwise or
  26. local p,c=1,0
  27. while a+b>0 do
  28. local ra,rb=a%2,b%2
  29. if ra+rb>0 then c=c+p end
  30. a,b,p=(a-ra)/2,(b-rb)/2,p*2
  31. end
  32. return c
  33. end
  34.  
  35. local function BitNOT(n)
  36. local p,c=1,0
  37. while n>0 do
  38. local r=n%2
  39. if r<1 then c=c+p end
  40. n,p=(n-r)/2,p*2
  41. end
  42. return c
  43. end
  44.  
  45. local function BitAND(a,b)--Bitwise and
  46. local p,c=1,0
  47. while a>0 and b>0 do
  48. local ra,rb=a%2,b%2
  49. if ra+rb>1 then c=c+p end
  50. a,b,p=(a-ra)/2,(b-rb)/2,p*2
  51. end
  52. return c
  53. end
  54.  
  55. function lshift(x, by)
  56. return x * 2 ^ by
  57. end
  58.  
  59. function rshift(x, by)
  60. return math.floor(x / 2 ^ by)
  61. end
  62.  
  63. ----------------------------------------------
  64.  
  65. --[[
  66. int crc_init(void)
  67. {
  68. crc_deinit();
  69. pcrc_table = (unsigned int *)malloc(sizeof(int)*8*256);
  70. if(NULL == pcrc_table){
  71. printf("crc malloc error!\n");
  72. return 0;
  73. }
  74.  
  75. int i, j;
  76. unsigned int c;
  77. for (i=0;i<256;i++)
  78. {
  79. for (c=i,j=0;j<8;j++)
  80. c = (c & 1) ? (c>>1)^0xEDB88320L : (c>>1);
  81. pcrc_table[i] = c;
  82. }
  83. return 1;
  84. }
  85. ]]
  86.  
  87. for i=0, 255 do
  88. for j=0, 7 do
  89. c = i
  90. if (hasbit(c, 1)) then print (c) end
  91. end
  92. end
Advertisement
Add Comment
Please, Sign In to add comment