I have concocted a function from other peoples examples to find the powers of two in a prime decompostion, in the example below its $2^2=4$ gives {2,2}.

Select[FactorInteger[4], #[[1]] == 2 &] (*#[[1]] means part 1 {1,2}*)

Now this is all well and good (I think!) but I want the output in a format I can use numerically like 4 instead of {2,2}.

How might I achieve this simple task N[] does not work.

This answer is not what I'm looking for as it does not provide a usable numerical output but just changes format.


2 Answers 2


Is this what you are looking for?

It uses your code and just adds a bit to get the numeric result for you

n = 2^3*5*7*11;
Power @@ Select[FactorInteger[n], #[[1]] == 2 &][[1]]

(* 8 *)

The [[1]] at the end gets rid of the extra layer of {}

The Power @@ turns {2,3} into Power[2,3] and the result is 8


Not sure, but perhaps you could use IntegerExponent.


where n is the number you want factored, and p is the prime of interest. For your example,


returns 4.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.