Skip to main content
Filter by
Sorted by
Tagged with
3 votes
1 answer
128 views

I am writing firmware for a microcontroller. (In this specific case it is a Microchip PIC, but I am looking for an answer that is equally applicable to any brand of microcontroller.) Arduino has a map ...
Sod Almighty's user avatar
  • 1,866
4 votes
3 answers
187 views

My platform is x86_64, and assume there are 3 variables whose types are all uint16_t: uint16_t a, b, c; And for the following two code snippets: (1) uint16_t tmp = b - a; uint16_t result1 = c - tmp; ...
Nan Xiao's user avatar
  • 17.8k
0 votes
1 answer
55 views

Is there any way to do wrapping operations (addition, multiplication, SUM) on bigint columns? By this I mean the standard method of wrapping addition in other programming languages on integer types of ...
Mark's user avatar
  • 81
2 votes
1 answer
127 views

The title may seem odd, but I'm not sure what else to call it. If you have suggestions please let me know and I'll edit. Consider this uint8_t lo = 0x11; // given uint8_t hi = 0x22; // given uint16_t ...
sudo pkill depression's user avatar
4 votes
1 answer
134 views

I am looking for an efficient algorithm that computes arithmetic shift-right of integers that rounds to nearest integer with halfway rounding toward zero behavior. An answer can be a proper ...
ksaa's user avatar
  • 83
0 votes
1 answer
145 views

A single 1 byte could be from 0 to 255. I intend to rescale it to be from 0 to 7. I have done this: bit8 := uint8(136) // To re-scale 1 byte from 0 to 2^3-1 i.e. 0 to 7 bit3 := bit8 / 0xff * 0b0111 ...
Megidd's user avatar
  • 8,233
1 vote
1 answer
110 views

To be clear, I am certain that the derivation below is incorrect, but I am hoping someone can point out where in my "proof" I am wrong. I am trying to prove that the x86 instruction setb ...
EE18's user avatar
  • 201
5 votes
4 answers
341 views

I have two arrays, a and b. Each contain 16 bytes and I would like to add each b[i] to their corresponding a[i]. The arrays do not overlap and also I know that the resulting sums always fit in a byte ...
adrianton3's user avatar
  • 2,378
0 votes
0 answers
46 views

I'm writing a program in assembly that simulates multiplication via iterative addition. I have the algorithm done, and for my first test case, I set my multiplicand to 50. Upon transferring this value,...
Hydro's user avatar
  • 1
4 votes
1 answer
98 views

I would like to compute (a*b)/c in Java in the most efficient way where: a, b and c are unsigned long values (guaranteed to fit in 63 bits, i.e. with zero sign bit) The result is also guaranteed to ...
mikera's user avatar
  • 107k
-1 votes
1 answer
175 views

Found a bug in my code and noticed the following, when subtracting 2 numbers like unsigned int a, b (with b > a) signed long result = a - b The result is always positive, even though b is larger. I ...
user avatar
-3 votes
4 answers
273 views

How to compute ⌊𝑥÷𝑐⌋ for a variable integer 𝑥 and a fixed-point rational number 𝑐≥1 precisely? The input 𝑥 ∈ [0, INT_MAX] is stored in a variable of type int, 𝑐 ∈ [1, INT_MAX] is given as a ...
AlMa1r's user avatar
  • 1
1 vote
0 answers
136 views

I am trying to do some computations on big numbers, using the GMP library. I am trying to understand how could I indicate GMP to use either signed or unsigned arithmetics. Let's say that I have two &...
user avatar
1 vote
2 answers
155 views

I am trying to translate simple JS code to C and/or Perl but I found a discrepancy in behaviour when doing arithmetic operations (+ - * / << >>) on integers and the result overflows. I ...
bliako's user avatar
  • 1,221
7 votes
3 answers
2k views

I'm looking for a convenient idiom to check if a multiplication of two signed integers (longs or long longs) would overflow since signed arithmetic overflow is undefined behavior in C and C++. I'm ...
user3188445's user avatar
  • 5,006
2 votes
1 answer
104 views

I have this image: HI00008918.png I want to apply a logarithmic function (f(x) = (1/a)*log(x + 1), where a = 0.01) on the image... So this is the code: import numpy as np import matplotlib.pyplot as ...
Gustavo Henrique's user avatar
0 votes
0 answers
75 views

I have an arithmetic expression containing Var, and I need to match it to the following format: Step * Var + Offset If it can be represented in this form, I need to get Step and Offset values. If not, ...
Yui Rio's user avatar
  • 41
-2 votes
2 answers
286 views

Imagine we are tasked with using an idealized scientific calculator which has the following properties: no direct support for bitwise operations, or for base conversions (eg cannot simply "...
HappMacDonald's user avatar
2 votes
1 answer
223 views

What is the minimum odd number that can be accurately represented with a float? Assume that the float is represented with 32 bits where: 1 bit is used for the sign, 8 bits for the exponent and 23 bits ...
Saiko's user avatar
  • 41
0 votes
1 answer
209 views

I'm a fairly advanced programmer (experience in Java, Python, C#, C, C++) who is now trying to learn Rust for the first time. Rust is quite different from any language I've tried before, so I'm ...
Matthias Verstraete's user avatar
0 votes
2 answers
67 views

I have code :get_transaltion(&(arr[1/2]) ) The array is of structures that each contain an array of 3 places, which places does the function accept? I edited the array in the first place in the ...
Ino's user avatar
  • 31
1 vote
1 answer
68 views

while 1: x=+1 pic = pyautogui.screenshot() pic.save(str(x)+".png", "PNG") print(x) time.sleep(5) X won't increase every time the loop, loops I want the ...
Pavlo Mazepa's user avatar
0 votes
2 answers
4k views

I want to perfom a simple operation: b+g+r b,g,r variables are integrers and have value below 256. I get Overflow Warning and wrong results. The problem is that the operation is simple(result not ...
Qwerth's user avatar
  • 21
1 vote
0 answers
53 views

int i=1; int n = (++i)+(++i); In C++ the above code has undefined behavior. I want to know in Java, does it have defined behavior and give the expected answer n=5 in this case. In Java, the order of ...
Yang Zhao's user avatar
  • 325
1 vote
1 answer
331 views

Matlab implements saturation arithmetic instead of wrapping on overflow for integers. While understanding the difference between the two, but not necessarily finer nuances, I wonder what was the ...
Ilya Kurnosov's user avatar
5 votes
1 answer
145 views

The following program: #include <iostream> #include <string> int main () { unsigned char result1 {0}; unsigned char result2 {0}; result1 = (result1 - 1) % 8; result2 = ...
JosF's user avatar
  • 153
1 vote
2 answers
233 views

So let's say if the list is [2,5,14,18,44], what I want to find out is what the biggest sum of two numbers under 60 would be. So the correct answer should be (14,44) Right now I am calculating every ...
Aaron Grace's user avatar
3 votes
1 answer
226 views

I'd like some help in understanding and fixing an SBCL compiler note that says: ; in: DEFUN PRINT-SEARCH-PROGRESS-GRAPH ; (- (1+ WOULDWORK-PKG::*N*) ; (LENGTH WOULDWORK-PKG::*L*)) ; ; note: ...
davypough's user avatar
  • 1,951
-2 votes
3 answers
88 views

i've been tinkering around, and i have googled and searched about bitwise operations. and i think i understand some of it, however i have a piece of code i have copied from someone online which allows ...
Michael Silva's user avatar
-2 votes
1 answer
1k views

#include<bits/stdc++.h> using namespace std; int main() { int n,m,z; cout<<"enter n: "; cin>>n; z=n; int count=0; while(n>0){ m = n % 10; if(z%...
Nazrul Hoda's user avatar
0 votes
2 answers
87 views

I was making a code that adds a summation for a specific formula, but the sum is always 0 for some reason. What is the reason nothing is adding? I think maybe it is the declaration of int and double ...
BeansAndRice's user avatar
0 votes
1 answer
75 views

I have the the following code where the results exceeds the limit an integer type variable can store and need to understand why I am getting this result (268,435,456=2^28) public static void main(...
Biryanii's user avatar
2 votes
3 answers
80 views

I was solving a question on Codechef and I encountered this problem. Here is the link to the question. https://www.codechef.com/LP0TO101/problems/FLOW013 Basically we are given three angles and we ...
JavaBoi's user avatar
  • 37
0 votes
4 answers
114 views

The function must return the sum of all integers between from and to including these numbers. For example, arithmeticSum(2,4) should be 9 because 2+3+4 = 9. This is the code right now, i can't change ...
Mattias's user avatar
  • 13
0 votes
0 answers
265 views

I would like to rename files names in folder using math operation. The simplest example for multiply *2 of n-th element doesn't work: cd c:\my_folder\ $n = 38 ls | Sort-Object LastWriteTime | %{Rename-...
Jan Nowak's user avatar
0 votes
2 answers
142 views

I have the following code in Java : int a=5,b=10,c; c = ++b * ++a - a++ ; System.out.println(c); Now referring to the Java operators precedence table :- Table We will first evaluate the postfix a++ ...
Anshul V. Kumar's user avatar
65 votes
4 answers
8k views

I have an int x. For simplicity, say ints occupy the range -2^31 to 2^31-1. I want to compute 2*x-1. I allow x to be any value 0 <= x <= 2^30. If I compute 2*(2^30), I get 2^31, which is an ...
mbang's user avatar
  • 865
0 votes
2 answers
47 views

I need the variable $tsp to be evenly added to the value in the "count" field, but only in those fields where the "count" is greater than 0 . $tsp = 9; $fin = [ "1701"...
Termate's user avatar
  • 17
0 votes
2 answers
938 views

I created a function seriesSum to return a sum of the series of a number, and I used long long return data type but it returns a negative number if I insert for example 46341 output will be -...
Jalal Hammash's user avatar
3 votes
3 answers
159 views

My professor gave us this java snippet during a lecture and I don't understand why it outputs 12. int b = 9; b = b + (b = 3); System.out.println( "b = " + b ); My thinking is that since ...
S. King's user avatar
  • 53
0 votes
1 answer
213 views

I wrote this code to find out the average of any 3 numbers. Please help me out. I'd like to know where it went wrong. I wrote the same code in a new file and that was executed without any issues. This ...
Boson's user avatar
  • 1
0 votes
0 answers
33 views

Im currently learning 8086 assembly at school, im using emu8086, i was playing around with some signed arithmetic and this occured. if i use the SUB instruction to subtract 15(0FH) from -16(F0H) with ...
blake 's user avatar
  • 107
-3 votes
1 answer
454 views

what are Hybrid Integers mentioned in this problem and what are applications of Hybrid Integers?
SaurabhDeshpande's user avatar
0 votes
2 answers
266 views

I want to create a razor component allowing to enter int or float numbers and increment or decrement them using a spin control. However, I have no idea to tell the Blazor generator / C# compiler how ...
Razzupaltuff's user avatar
  • 2,309
0 votes
1 answer
448 views

I would like to have a compile-time check that taking the least common multiple of two numbers doesn't overflow. Difficulty: regarding std::lcm, The behavior is undefined if |m|, |n|, or the least ...
Daniel McLaury's user avatar
7 votes
1 answer
3k views

I was wondering whether x**2 or x*x is faster def sqr(x): for i in range (20): x = x**2 return x def sqr_(x): for i in range (20): x = x*x return x When I time it, ...
goku's user avatar
  • 337
2 votes
0 answers
60 views

I have this template that wrap an unsigned integer type (any) : template<std::unsigned_integral T> struct base_dig_t {T m_data;}; Then I have this template to modify the behavior ...
Earendil's user avatar
-1 votes
1 answer
71 views

I am making a triangle area calculator, but it only show 0 instead of answer, It must be the formula 1/2 * ab sin c , can someone tell me what should I change to make it work. #include <stdio.h> ...
user18837503's user avatar
2 votes
1 answer
495 views

I am performing arithmetic operations on integers in a checked scope in C#/.NET, in order to catch when an overflow happens. I want to find out if the overflow was positive or negative, in a short, ...
Helena's user avatar
  • 1,127
1 vote
6 answers
210 views

Having a minor issue with the return value of this function for large parameters (works fine for smaller ones). Here is the code: def pyramid_blocks(n, m, h): return int(h*n*m + (h*h-h)*(3*n+3*m+2*h-...
Jacopo Stifani's user avatar

1
2 3 4 5
10