BitPunch McEliece  v0.0.4
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
int.c
Go to the documentation of this file.
1 /*
2 This file is part of BitPunch
3 Copyright (C) 2013-2015 Frantisek Uhrecky <frantisek.uhrecky[what here]gmail.com>
4 Copyright (C) 2013-2014 Andrej Gulyas <andrej.guly[what here]gmail.com>
5 Copyright (C) 2013-2014 Marek Klein <kleinmrk[what here]gmail.com>
6 Copyright (C) 2013-2014 Filip Machovec <filipmachovec[what here]yahoo.com>
7 Copyright (C) 2013-2014 Jozef Kudlac <jozef[what here]kudlac.sk>
8 
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "int.h"
23 
24 int BPU_isPrime(int n) {
25  int i;
26  if (n == 2)
27  return 1;
28  for (i = 2; i <= n/2.0; i++) { //TODO: import math.h and use sqrt(n)
29  if (n % i == 0)
30  return 0;
31  }
32  return 1;
33 }
34 
35 int msb32(uint32_t x, int start, int len, int ele_size) {
36  // crop lenght to half
37  len /= 2;
38 
39  // last recursion
40  if (len == 1) {
41  // return position of highest bit
42  if ((x >> len) == 1ul)
43  return start+1;
44  else
45  return start;
46  }
47 
48  // right half of integer
49  if ((x >> len) != 0ul) {
50  start += len;
51  x >>= len;
52  }
53  // left half of integer
54  else {
55  x <<= ele_size - len;
56  x >>= ele_size - len;
57  }
58 
59  // recursion
60  return msb32(x, start, len, ele_size);
61 }
int msb32(uint32_t x, int start, int len, int ele_size)
Definition: int.c:35
int BPU_isPrime(int n)
Definition: int.c:24