diff options
author | Oskar <[email protected]> | 2024-08-21 18:08:30 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-08-21 18:08:30 +0200 |
commit | e747f69eb9b34f2c99472ca1cd17e049c1b74c9c (patch) | |
tree | bf082a6c2a00f29cdc81f5a2b9b1699c94eb1128 | |
parent | 5562f3eb30418f33ba2d2b4634e8d7a2f5d49dc5 (diff) |
more
-rw-r--r-- | 4p25.cpp | 28 | ||||
-rw-r--r-- | 4p26.cpp | 20 | ||||
-rw-r--r-- | 4p27.cpp | 30 | ||||
-rw-r--r-- | bitwise-operator-tests.cpp | 6 | ||||
-rw-r--r-- | gede2.ini | 17 |
5 files changed, 101 insertions, 0 deletions
diff --git a/4p25.cpp b/4p25.cpp new file mode 100644 index 0000000..22070d3 --- /dev/null +++ b/4p25.cpp @@ -0,0 +1,28 @@ +#include <iostream> + +/* + * + * 4.25 + * + * + */ + +int main () { + + /* + + 01110001 (q) + NOT + 11111111 11111111 11111111 10001110 + << 6 + 11111111 11111111 11100011 10000000 (my own calculations) + 11111111 11111111 11100011 10000000 (output from gdb, added spaces) + (seems correct!) + */ + + // Quick little test where we can examine with GDB if i did it correctly. + int8_t ch = 0b01110001; + int32_t cf = ~ch << 6; + std::cout << cf << std::endl; + return 0; +} diff --git a/4p26.cpp b/4p26.cpp new file mode 100644 index 0000000..d8cb540 --- /dev/null +++ b/4p26.cpp @@ -0,0 +1,20 @@ + +/* + * + * 4.26 + * + * + */ + +int main () { + + /* + It's only gauranteed for an int to have + 16 bits. Most of the time on modern computers + we wont actually have 16 bit ints. But, to be + completely sure we use long so that we can + absolutely gaurantee that we have enough bits + so that we can set students to failed or passed. + */ + return 0; +} diff --git a/4p27.cpp b/4p27.cpp new file mode 100644 index 0000000..de8fb47 --- /dev/null +++ b/4p27.cpp @@ -0,0 +1,30 @@ +#include <iostream> + +/* + * + * 4.27 + * + * + */ + +int main () { + + uint32_t ul1 = 3; + uint32_t ul2 = 7; + + // 00000011 (ul1) + // 00000111 (ul2) + /* + ul1 AND ul2: + 00000011 + + ul1 OR ul2 + 00000111 + */ + + std::cout << (ul1 & ul2) << std::endl; // 3 + std::cout << (ul1 | ul2) << std::endl; // 7 + std::cout << (ul1 && ul2) << std::endl; // 1 (true) + std::cout << (ul1 || ul2) << std::endl; // 1 (true) + return 0; +} diff --git a/bitwise-operator-tests.cpp b/bitwise-operator-tests.cpp index 110d52e..8bfac1c 100644 --- a/bitwise-operator-tests.cpp +++ b/bitwise-operator-tests.cpp @@ -50,6 +50,12 @@ result of Quiz1 AND NOT(1UL << 27): 00000000 01100000 00010000 11100000 ------------------------------------------------------------------------------------------------------------------------- + +NOT(~) --- Inverts the operand +AND(&) --- If both operands contains 1 then it stays 1. Anything else becomes 0. +OR(|) --- If one or both of the operands have 1 then it becomes 1. Anything else becomes 0. +XOR(^) --- Turn to one if one operand has 1. If both have 1, or if both have 0 then turn to 0. + */ void cin_clear() { diff --git a/gede2.ini b/gede2.ini new file mode 100644 index 0000000..17e43c9 --- /dev/null +++ b/gede2.ini @@ -0,0 +1,17 @@ +Breakpoints="/home/oskar/code/primer/4p27.cpp:18;/home/oskar/code/primer/4p27.cpp:12"
+CoreDumpFile="./core"
+Download=1
+GdpPath="gdb"
+GoToRecentlyUsed=""
+InitCommands=""
+InitialBreakpoint="main"
+LastProgram="4p27"
+LastProgramArguments=""
+Mode=0
+ReuseBreakpoints=0
+RunningPid=0
+SerialBaudRate=1200
+SerialPort=""
+TcpHost="localhost"
+TcpPort=2000
+
|