---
title: "Reverse Intrger"  
description: "Reverse Intrger"  
author: "Steilla Mitchel"  
published: 2024-06-11  
updated: 2024-06-12  
canonical: https://www.mindstick.com/forum/160720/reverse-intrger  
category: "c#"  
tags: ["c#", ".net"]  
reading_time: 1 minute  

---

# Reverse Intrger

Given a signed 32-[bit](https://www.mindstick.com/forum/33411/how-we-tell-programmatically-if-i-m-running-in-64-bit-jvm-or-32-bit-jvm) [integer](https://answers.mindstick.com/qa/113667/write-code-for-roman-to-integer) `x`, return `x` *with its digits reversed*. If reversing `x` [causes](https://yourviews.mindstick.com/view/293/renovation-causes-wastage-of-resources) the [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) to go outside the signed 32-bit integer [range](https://www.mindstick.com/articles/23243/complete-troubleshooting-tips-for-belkin-n300-range-extender-setup) `[-231, 231 - 1]`, then return `0`.

**Assume the [environment](https://yourviews.mindstick.com/view/308/need-to-create-a-supportive-work-environment-for-women) does not allow you to [store](https://www.mindstick.com/articles/13125/tips-to-increase-sales-of-your-woocommerce-store) 64-bit integers (signed or unsigned).**

## Replies

### Reply by Ravi Vishwakarma

Let's write code for **Reverse Integer** in C#.

```cs
public static int ReverseIntergr(int number)
{
    //initlize value
    int result = 0;
    //check number negative or not
    bool IsNumberNegative = number < -1;
    if (IsNumberNegative)
    {
        number *= -1; // convert number if negative
    }
    //iterate number when number is grater than 0
    while (number > 0)
    {
        //assign value in result variable and add last digit of number
        result = result * 10 + number % 10;
        number /= 10;
    }
    //return the result, also check result is grater than UInt32.MaxValue
    return result > UInt32.MaxValue ? 0 : IsNumberNegative ? result * -1 : result;
}
```


---

Original Source: https://www.mindstick.com/forum/160720/reverse-intrger

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
