Search for a tool
2-Adic Valuation

Tool to calculate the 2-adic valuation v2(n)—the highest power of 2 dividing an integer—extract the odd part, count trailing binary zeros, and analyze divisibility by 2^k

Results

2-Adic Valuation -

Tag(s) : Arithmetics

Share
Share
dCode and more

dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!


Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!


Feedback and suggestions are welcome so that dCode offers the best '2-Adic Valuation' tool for free! Thank you!

2-Adic Valuation

2-adic Valuation

2-adic Valuation of an Integer



2-adic Valuation of a Fraction


2-adic Valuation of a Factorial


Answers to Questions (FAQ)

What is the 2-adic valuation? (Definition)

The 2-adic valuation, denoted $ v_2 $, is the function that measures the power of 2 dividing a number. For a non-zero integer $ n $, $ v_2(n) $ is the exponent of 2 in its prime factorization.

Example: $ 40 = 2^3 \times 5 $, so $ v_2(40) = 3 $

More generally, $ v_2(n) $ indicates how many times $ n $ is divisible by 2. By convention, $ v_2(0) = +\infty $ and $ v_2(-n) = v_2(n) $

How to calculate v2(n) for a natural number?

For a natural number $ n > 0 $, perform successive divisions by 2 and count the number of exact divisions before obtaining an odd quotient. This number is $ v_2(n) $. Equivalently, $ v_2(n) $ is the largest integer $ k $ such that $ 2^k $ divides $ n $.

Example: $ 40 = 8 \times 5 = 2^3 \times 5 $, so $ v_2(40) = 3 $.

An even number satisfies $ v_2(n) \geq 1 $, while an odd number satisfies $ v_2(n) = 0 $

How to calculate $ v_2 $ from the binary representation?

For a non-zero positive integer, write the number in base 2 and count the trailing zeros, i.e., the zeros located to the right of the binary representation. This number is exactly $ v_2(n) $.

Example: $ 12 $ is written $ 1100_{(2)} $ and has two trailing zeros, so $ v_2(12) = 2 $

Example: $ 7 $ is written $ 111_2 $ and has no trailing zeros, so $ v_2(7) = 0 $

How to calculate $ v_2 $ for a rational $ a/b $?

For a non-zero rational $ a/b $, with $ a \neq 0 $ and $ b \neq 0 $, extend the valuation by the formula $ v_2(a/b) = v_2(a) - v_2(b) $. This definition does not depend on the chosen representation of the rational.

Example: $ v_2(3/16) = v_2(3) - v_2(16) = 0 - 4 = -4 $. A negative valuation means that the denominator contains, after simplification, more factors of 2 than the numerator.

How to calculate $ v_2(n!) $ (factorial)?

Use Legendre's formula $ v_2(n!) = \sum_{k\geq1} \left\lfloor n/2^k \right\rfloor $

The sum stops as soon as $ 2^k > n $

Example: $ v_2(10!) = \lfloor 10/2 \rfloor + \lfloor 10/4 \rfloor + \lfloor 10/8 \rfloor = 5+2+1 = 8 $.

Another useful formula is $ v_2(n!) = n-s_2(n) $, where $ s_2(n) $ is the number of 1 digits of $ n $ written in base 2

Source code

dCode retains ownership of the "2-Adic Valuation" source code. Any algorithm for the "2-Adic Valuation" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "2-Adic Valuation" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "2-Adic Valuation" or any other element are not public (except explicit open source licence). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.

Cite dCode

The content of the page "2-Adic Valuation" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source (Creative Commons CC-BY free distribution license).

Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).

To cite dCode.fr on another website, use the link: https://www.dcode.fr/2-adic-valuation

In a scientific article or book, the recommended bibliographic citation is: 2-Adic Valuation on dCode.fr [online website], retrieved on 2026-08-31, https://www.dcode.fr/2-adic-valuation

Need Help ?

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!

Questions / Comments

Feedback and suggestions are welcome so that dCode offers the best '2-Adic Valuation' tool for free! Thank you!


https://www.dcode.fr/2-adic-valuation
© 2026 dCode — The ultimate collection of tools for games, math, and puzzles.
 
Feedback