All Questions
2,831 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
-4
votes
1
answer
184
views
Why am I getting "nan" when I try to overload the modulo operator in C++? [closed]
I am trying to overload the % operator in C++ to make it do division instead of modulo. For example, 5 % 4 should give me 1.25 after overloading.
But I get "nan". Why?
This is the code I ...
0
votes
7
answers
319
views
How does '0' + (n % 10) convert an integer digit to its character representation in C?
I'm learning about converting numbers to characters in C, and I came across the expression:
char c = '0' + (n % 10);
I understand that '0' is a character and n % 10 extracts the last digit of a ...
4
votes
2
answers
92
views
Excel Cyclical Offset
I'm attempting to pull in multiples columns (with specific ranges) into a single column. I've been running in circles (pardon the pun) to no avail. Here is my formula thus far on sheet3!A2:
=OFFSET(...
0
votes
2
answers
153
views
Why can't you check if a negative number is odd by comparing the remainder of division by 2 with 1? [duplicate]
When I compare remainder with 1, it doesn't work as I expect:
int t = (-3 % 2) == 1;
printf("is odd: %d\n", t);
result is: 0
When I compare with 0:
int t = (-3 % 2) != 0
then it works.
...
3
votes
2
answers
151
views
Convert floating-point value to cyclic range?
I'm not sure if I'm using the right terminology, but occasionally I find myself needing to canonicalize a floating-point value to a range in a cyclic manner. (This can be useful, for instance, for ...
0
votes
0
answers
117
views
The fastest MOD algorithm in C++ for extremely large uint_64_t numbers stored in an array
I am working with extremely large numbers and would like to verify my Karatsuba multiplication result ((2^136279841)-1)^2 which needs (532 344 * _m256i_epi64)^2 i.e. 4,258,752 uint64_t to store the ...
3
votes
2
answers
204
views
C++ modulo returning inconsistent results
Can someone tell me why these two functions return different results?
After running code
#include <string>
#include <stdio.h>
#include <iostream>
using namespace std;
int returnN(...
1
vote
0
answers
72
views
How to evenly divide a total value into predefined values with buffers in Python?
I've been working on a fence calculation tool that breaks down a total length, as equally as possible, into components (rails and posts) using a predefined set of rail lengths. The user can choose a ...
0
votes
0
answers
65
views
Can anyone explain why this RSA calculation not working
I made a RSA encrypting and decrypting program.
Everything works well as it is suppose to be. However when I decrypt the message, it doesn't give me the message.
Can somebody check which part is wrong ...
0
votes
0
answers
76
views
Wrapping a number within a specific range
I have come across the below wrapping formula to wrap a number x within a range [min, max].
const wrappedValue = (x - min) % (max - min + 1) + min;
I am trying to understand the formula.
Specifically,...
1
vote
2
answers
98
views
Shifting a number based on the remainder of it divided by 4 - C
I have a function implemented which reverses the bits in a number. The number of bits in the number to be reversed can vary. However, of course it must be shifted to the left at the end to align with ...
2
votes
3
answers
138
views
How to divide the numbers between two number and see how many numbers there modulus = 0
I have a task that forbids me from using an array or String or loops only if conditions or switch cases. The task is that I need to take three numbers from the user and see the how many numbers ...
0
votes
0
answers
38
views
Problems repeating Shekhar's calculations in his article on Asymmetric and Post Quantum Cryptography
This is a great article at
https://medium.com/@shekhar.siva2609/asymmetric-encryption-and-post-quantum-cryptography-bea4a5a08ae5,
particularly if you're interested in Elliptic curve cryptography.
...
0
votes
0
answers
86
views
C++ - Questions about bit shift operators (<< and >>) [duplicate]
Consider the below code:
std::string g_CharTable = "stjkloptrew23456mncv891TZUIOPAS";
std::uint32_t value = 123456789
std::string hash;
for (std::size_t i = 0; i < 5; ++i)
{
...
0
votes
2
answers
93
views
How to convert a time string measured in 24 hours cycle to 12 hours cycle?
I have a stored value of an hour in a 24-hour format in a variable named hour. My task is to convert this value to a 12-hour format and print the result.
I tried while-loops, if-elif-statements. I ...