Skip to main content
3 votes
1 answer
123 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,856
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.7k
0 votes
1 answer
53 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
130 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
144 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,223
1 vote
1 answer
108 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
339 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
96 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
271 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
134 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
154 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
  • 4,990

15 30 50 per page
1
2 3 4 5
32