Website Summary Files Commits Branches @commit @diff @stats
path: root / pract_SI / Pract. 05 / Solutions / task3.cpp
diff options
context:
space:
mode:
1 files changed, 50 insertions, 0 deletions
-rw-r--r--pract_SI/Pract. 05/Solutions/task3.cpp50
diff --git a/pract_SI/Pract. 05/Solutions/task3.cpp b/pract_SI/Pract. 05/Solutions/task3.cpp
new file mode 100644
index 0000000..b8693d9
--- /dev/null
+++ b/pract_SI/Pract. 05/Solutions/task3.cpp
@@ -0,0 +1,50 @@
+long long toBinary(int number)
+{
+ if (number < 0)
+ number *= -1;
+
+ int buffer[MAX_POWTWO_SIZE];
+ int size = 0;
+
+ while (number > 0)
+ {
+ buffer[size] = number % 2;
+ number /= 2;
+ size++;
+ }
+
+ long long convertedToBinary = 0;
+ long long multiply = 1;
+ for (int i = 0; i < size; i++)
+ {
+ convertedToBinary += buffer[i] * multiply;
+ multiply *= 10;
+ }
+
+ return convertedToBinary;
+}
+
+void convertToBinary(long long &number)
+{
+ if (number < 0)
+ number *= -1;
+
+ int buffer[MAX_POWTWO_SIZE];
+ int size = 0;
+
+ while (number > 0)
+ {
+ buffer[size] = number % 2;
+ number /= 2;
+ size++;
+ }
+
+ long long multiply = 1;
+ for (int i = 0; i < size; i++)
+ {
+ if(buffer[i] == 1)
+ number += multiply;
+
+ multiply *= 10;
+ }
+} \ No newline at end of file