1. Notation and Preliminaries
We work with nonnegative integers in binary. Bits are indexed from 0 (LSB). For
,
Let . In , let be the carry entering bit i (set ), and write for the carry exiting bit i. In with , define analogously with . For bitwise operations we use , , , and shifts .
Proposition 1 (Folklore identities).
For all ,
Proof. Count ones positionwise: XOR marks disagreement; OR marks at-least-one. □
2. Carry and Borrow Decompositions
Fix such that . All sums below are taken over . We also make and explicit (final carry/borrow).
Theorem 1 (Addition: exact carry decomposition).
For all , with ,
Proof. At bit i: . Sum and identify , , . □
Theorem 2 (Subtraction: exact borrow decomposition).
Let . With ,
For we have .
Remark 1 (Carries and 2-adic valuation).
The number of carries in adding x and y equals the 2-adic valuation of :
3. Shift–Mask Tools and Constructive Corollaries
Lemma 1 (Shifts). For , and .
Lemma 2 (Mask disjointness). Let be a run of ℓ consecutive 1s, disjoint from the support of x. Then .
Corollary 1 (Forcing a target Hamming weight). For any x and any integer , there exists a mask M (a disjoint run of ones) such that .
4. Applications and Bounds
Write for the active bit-length, and for the total number of carries (so by rem:kummer).
Corollary 2 (Bit-length lower bound).
From (3) and we have
since . This bound is often sharp up to an additive constant.
Corollary 3 (Kummer-based control).
Using ,
Hence any upper bound on (e.g., via binary digit overlaps of x and y) yields a corresponding lower bound on .
Corollary 4 (Bitwise combinations).
For any ,
with equality iff .
Algorithmic angle
Computing
directly is
bit-operations (same as addition). The identity (
3) expresses
as a linear form in the carry profile; thus any algorithm or hardware that already exposes carries (e.g., prefix adders like Kogge–Stone/Brent–Kung) gives
for free after addition (one pass of counting). This is useful in:
Hardware angle
In CMOS, dynamic power correlates with bit flips and, in many platforms, with Hamming weights of buses. The carry chain length
C (and its distribution) interacts with toggle activity; (
3) isolates the linear influence of
C on the resulting weight. This connects to prefix adder analyses (Kogge–Stone [
6], Brent–Kung [
7]).
Side-channel angle
Simple/Differential Power Analysis often models traces via Hamming weight or Hamming distance. Identity (
3) provides a
deterministic link between the weight after addition and the carry chain (which itself depends on operand bit patterns), informing leakage simulators and countermeasures (e.g., operand randomization). See Kocher–Jaffe–Jun [
9].
Remark 2
(Towards multiplicative operations).
For multiplication, is a sum of shifted copies of y; hence
by a naive union bound (collisions and carries can reduce the weight). A refined analysis requires carry bookkeeping across the partial-product convolution; we leave a tight identity as future work.
5. Worked Examples and Sanity Checks
Bits are indexed from 0. We verify Theorems 1 and 2 on small pairs.
Example A (Addition)
Let
,
. Then
,
. Active carries:
Thus
. By (
3):
Example B (Subtraction)
Let
,
. Then
has
. A borrow trace gives an active window with
, hence
plus a single bit created by the borrow cascade, totaling 2, matching (
4).
A small table:
Table 1.
Sanity checks consistent with (
3) and (
4).
Table 1.
Sanity checks consistent with (
3) and (
4).
| x |
y |
|
|
|
|
|
|
| 5 |
3 |
2 |
2 |
8 |
1 |
2 |
1 |
| 29 |
23 |
4 |
4 |
52 |
3 |
6 |
2 |
| 37 |
14 |
3 |
3 |
51 |
3 |
23 |
4 |
6. 2-Adic Perspective and Kummer Linkage
Kummer’s theorem states that the exponent of a prime
p dividing
equals the number of carries when adding
v and
in base
p. For
,
Combining with thm:add yields an explicit reformulation of in terms of and .
7. Positioning, Prior Art, and Contributions
Digital sums in base 2 go back to Delange and Coquet; Allouche–Shallit systematized many properties via automata. The identities here are elementary but presented as a consolidated, explicit package with constructive corollaries and a 2-adic bridge. Connections to prefix adders and leakage models highlight practical relevance.
8. Conclusions
We provided exact weight identities under addition, subtraction, and bitwise operations; shift–mask tools; bounds in terms of bl and Kummer; and application pointers (algorithms, hardware, side-channels). Future work: tight multiplicative identities and carry-profile statistics.
References
- H. Delange, Sur la fonction sommatoire de la fonction somme des chiffres, Enseign. Math. 1975, 21, 31–47.
- J. Coquet, A summation formula related to the binary digits. Invent. Math. 1983, 73, 107–115. [CrossRef]
- J.-P. Allouche and J. Shallit, Automatic Sequences: Theory, Applications, Generalizations, Cambridge Univ. Press, 2003.
- E. E. Kummer, Über die ergänzungssätze zu den allgemeinen Reciprocitätsgesetzen. J. Reine Angew. Math. 1852, 44, 93–146.
- P. Flajolet and R. Sedgewick, Analytic Combinatorics, Cambridge Univ. Press, 2009.
- P. M. Kogge and H. S. Stone, A parallel algorithm for the efficient solution of a general class of recurrences. IEEE Trans. Comput. 1973, C-22, 786–793. [CrossRef]
- R. P. Brent and H. T. Kung, A regular layout for parallel adders. IEEE Trans. Comput. 1982, C-31, 260–264. [CrossRef]
- D. E. Knuth, The Art of Computer Programming, Vol. 2: Seminumerical Algorithms, 3rd ed., Addison-Wesley, 1998.
- P. Kocher, J. Jaffe, and B. Jun, Differential Power Analysis, CRYPTO 1999, LNCS 1666, 388–397.
|
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).