cmake
This commit is contained in:
parent
e16d783b10
commit
edd45b209b
0
04_UDEF/Testat/Testat.cpp
Normal file
0
04_UDEF/Testat/Testat.cpp
Normal file
@ -2,38 +2,66 @@
|
||||
#include "../helpers/println.hpp"
|
||||
#include <iostream>
|
||||
|
||||
const int bitsPerOctet=8;
|
||||
const int bitsPerOctet = 8;
|
||||
|
||||
struct BinaryOctet {
|
||||
bool evenParity; // set to true if number of '1' in bitsAsDigits is even, false otherwise
|
||||
char bitsAsDigits[bitsPerOctet]; // bit values as chars
|
||||
BinaryOctet(int x=0);
|
||||
BinaryOctet(const BinaryOctet&) = default;
|
||||
bool evenParity; // set to true if number of '1' in bitsAsDigits is even, false otherwise
|
||||
char bitsAsDigits[bitsPerOctet]; // bit values as chars
|
||||
BinaryOctet(int x = 0);
|
||||
|
||||
BinaryOctet(const BinaryOctet &) = default;
|
||||
};
|
||||
|
||||
BinaryOctet::BinaryOctet(int x){
|
||||
// TODO: implement
|
||||
BinaryOctet::BinaryOctet(int x) {
|
||||
int length = std::to_string(x).length() * 4;
|
||||
while (x >= 1) {
|
||||
bitsAsDigits[length] = (x % 2 == 0) ? '1' : '0';
|
||||
x = x / 2;
|
||||
length--;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (char c : bitsAsDigits) {
|
||||
if (c == '1') i++;
|
||||
}
|
||||
evenParity = i % 2 == 0;
|
||||
}
|
||||
|
||||
bool operator!=(BinaryOctet a, BinaryOctet b) {
|
||||
|
||||
BinaryOctet doCalculation(BinaryOctet a, BinaryOctet b){
|
||||
BinaryOctet result;
|
||||
|
||||
for(; a != b; b--){
|
||||
a = a + 1;
|
||||
a = a / b;
|
||||
}
|
||||
result = a + b;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
BinaryOctet operator--(BinaryOctet &id, int) {
|
||||
|
||||
}
|
||||
|
||||
BinaryOctet operator+(BinaryOctet a, BinaryOctet b) {
|
||||
|
||||
}
|
||||
|
||||
BinaryOctet operator/(BinaryOctet a, BinaryOctet b) {
|
||||
|
||||
}
|
||||
|
||||
BinaryOctet doCalculation(BinaryOctet a, BinaryOctet b) {
|
||||
BinaryOctet result;
|
||||
|
||||
for (; a != b; b--) {
|
||||
a = a + 1;
|
||||
a = a / b;
|
||||
}
|
||||
result = a + b;
|
||||
return result;
|
||||
}
|
||||
|
||||
// for println();
|
||||
std::string as_string(BinaryOctet a){
|
||||
std::string result = "(";
|
||||
// TODO: implement
|
||||
result += ")";
|
||||
return result;
|
||||
std::string as_string(BinaryOctet a) {
|
||||
std::string result = "(";
|
||||
for (char c : a.bitsAsDigits) {
|
||||
result += c;
|
||||
}
|
||||
result += ")";
|
||||
return result;
|
||||
}
|
||||
|
||||
// for std::cout
|
||||
@ -42,11 +70,12 @@ std::string as_string(BinaryOctet a){
|
||||
return os;
|
||||
}*/
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
BinaryOctet a = 0b00001111;
|
||||
BinaryOctet b = 0b00000110;
|
||||
println("result = ", doCalculation(a,b));
|
||||
//std::cout << "result = " << doCalculation(a,b) << std::endl;
|
||||
return 0;
|
||||
int main(int argc, char **argv) {
|
||||
BinaryOctet a = 0b00001111;
|
||||
BinaryOctet b = 0b00000110;
|
||||
println(new BinaryOctet(5));
|
||||
println(new BinaryOctet(5));
|
||||
//println("result = ", doCalculation(a,b));
|
||||
//std::cout << "result = " << doCalculation(a,b) << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
16
CMakeLists.txt
Normal file
16
CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.3)
|
||||
project(test_build)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
|
||||
|
||||
set(UDEF_1 UserDefinedTypes1)
|
||||
set(UDEF_1_SOURCE 04_UDEF/main_04_UDEF_e.cpp)
|
||||
add_executable(${UDEF_1} ${UDEF_1_SOURCE})
|
||||
|
||||
set(UDEF_2 UserDefinedTypes2)
|
||||
set(UDEF_2_SOURCE 04_UDEF/main_04_UDEF_a.cpp)
|
||||
add_executable(${UDEF_2} ${UDEF_2_SOURCE})
|
||||
|
||||
set(UDEF_TESTAT UserDefinedTypesTestat)
|
||||
set(UDEF_TESTAT_SOURCE 04_UDEF/Testat/Testat.cpp)
|
||||
add_executable(${UDEF_TESTAT} ${UDEF_TESTAT_SOURCE})
|
Loading…
Reference in New Issue
Block a user