-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconversion.cpp
More file actions
36 lines (24 loc) · 756 Bytes
/
conversion.cpp
File metadata and controls
36 lines (24 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "conversion.h"
#include "math.h"
int convElementListToState(int *elements, int size) {
int stateValue = 0;
for(int i=0; i < size; i++) {
stateValue = stateValue + pow(2,elements[i]-1);
}
}
void decToBinary(int decimalValue, int binaryValueSize, int *binaryValue)
{
for(int i = 0; i < binaryValueSize; i++) {
*binaryValue = decimalValue - floor(decimalValue/2)*2;
decimalValue = floor(decimalValue/2);
binaryValue++;
}
}
int binaryToDec(int *binaryValue, int binaryValueSize) {
int decValue = 0;
for(int i = 0; i < binaryValueSize; i++) {
if (binaryValue[i])
decValue = decValue + 2^i;
}
return decValue;
}