gives the integer whose digits are reversed with respect to those of the integer n.
IntegerReverse[n,b]
gives the integer whose digits in base b are reversed with respect to those of n.
IntegerReverse[n,b,len]
gives the integer with reversed digits after padding n with zeros on the left to have len digits.
IntegerReverse
gives the integer whose digits are reversed with respect to those of the integer n.
IntegerReverse[n,b]
gives the integer whose digits in base b are reversed with respect to those of n.
IntegerReverse[n,b,len]
gives the integer with reversed digits after padding n with zeros on the left to have len digits.
Details
- IntegerReverse[n] always returns a positive integer.
- IntegerReverse[0,b,len] returns 0 for any base b and digits length len.
Examples
open all close allBasic Examples (3)
Reverse the digits of an integer:
IntegerReverse[123456]Reverse the binary digits of an integer:
IntegerReverse[2015, 2]The result coincides with the input because that number is a binary palindrome:
IntegerDigits[%, 2]Reverse the digits of an integer after padding it with zeros on the left:
IntegerReverse[1234, 10, 6]Scope (5)
Reverse the base 10 digits of an integer:
IntegerReverse[1234]Reverse the digits of an integer in a different base:
IntegerReverse[1234, 2]That is equivalent to this sequence of transformations:
FromDigits[Reverse[IntegerDigits[1234, 2]], 2]Reverse the digits of an integer after padding with zeros on the left:
IntegerReverse[1234, 10, 6]Reverse the digits of an integer using a mixed radix:
IntegerReverse[1234, MixedRadix[{7, 11}]]That is equivalent to this sequence of transformations:
With[{mr = MixedRadix[{7, 11}]}, FromDigits[Reverse[IntegerDigits[1234, mr]], mr]]Reverse the respective digits of a list of integers:
IntegerReverse[{123, 234, 345, 456}]Applications (2)
Generate reversal permutations of degree bn:
reversalperm[n_, b_] := IntegerReverse[Range[0, b ^ n - 1], b, n] + 1;Bit reversal permutations use base 2:
Table[reversalperm[n, 2], {n, 0, 5}]PermutationListQ /@ %perms = Table[reversalperm[n, 3], {n, 0, 4}]PermutationListQ /@ permsReversal is involutive, therefore the permutations are all formed by 2-cycles:
PermutationCycles /@ permsline[{p1_, p2_}] := {PointSize[Large], Point[{p1, p2}], Line[{p1, p2}]}With[{n = 4}, Graphics[line /@ Thread[{Thread[{0, Range[2 ^ n]}], Thread[{2 ^ (n - 1), reversalperm[n, 2]}]}]]]This returns the first n numbers of the van der Corput sequence in base b:
vanDerCorput[n_, b_] := With[{range = Range[n]}, IntegerReverse[range, b] / b ^ IntegerLength[range, b]]The first 20 elements of the decimal van der Corput sequence:
vanDerCorput[20, 10]The first 20 elements of the binary van der Corput sequence:
vanDerCorput[20, 2]Show how it progressively fills the interval from 0 to 1:
ListPlot[Flatten[Table[Thread[{vanDerCorput[n, 10], n}], {n, 400}], 1], ImageSize -> Medium]Properties & Relations (3)
Digit reversal strongly depends on the base used:
Table[IntegerReverse[8235, b], {b, 2, 16}]ListPlot[%]When the last digit of an integer is different from zero, IntegerReverse is its own inverse:
IntegerReverse[842]IntegerReverse[%]Otherwise, a different number is obtained:
IntegerReverse[84200]IntegerReverse[%]Specify the number of digits in the second operation to obtain the original result:
IntegerReverse[84200]IntegerReverse[%, 10, 5]Addition of an integer n and IntegerReverse[n] gives a palindromic number in some cases:
With[{n = 253147627}, n + IntegerReverse[n]]PalindromeQ[%]With[{n = 55}, n + IntegerReverse[n]]PalindromeQ[%]It is conjectured that this algorithm eventually produces a palindromic number for every decimal input:
algorithm[n_] := NestWhile[# + IntegerReverse[#]&, n, Not[PalindromeQ[#]]&]algorithm[48]algorithm[89]PalindromeQ[%]There are numbers for which it is not known whether the algorithm succeeds, the smallest being 196:
TimeConstrained[algorithm[196], 1]Related Guides
History
Text
Wolfram Research (2015), IntegerReverse, Wolfram Language function, https://reference.wolfram.com/language/ref/IntegerReverse.html.
CMS
Wolfram Language. 2015. "IntegerReverse." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/IntegerReverse.html.
APA
Wolfram Language. (2015). IntegerReverse. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/IntegerReverse.html
BibTeX
@misc{reference.wolfram_2026_integerreverse, author="Wolfram Research", title="{IntegerReverse}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/IntegerReverse.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_integerreverse, organization={Wolfram Research}, title={IntegerReverse}, year={2015}, url={https://reference.wolfram.com/language/ref/IntegerReverse.html}, note=[Accessed: 12-June-2026]}