C# Convert ToUInt32() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Convert

Definition

In C#, Convert.ToUInt32 returns a uint—unsigned 32-bit integer from 0 to 4,294,967,295.

Use it for sizes and IDs that never go negative. Negatives throw OverflowException.

This is a static member of System.Convert. You call it with the type name, such as Convert.ToUInt32(...). Convert is the everyday API for converting between common CLR types in C#.

Syntax

Convert text or numbers into a uint.

C#
uint a = Convert.ToUInt32("4000000000");
uint b = Convert.ToUInt32(20);
uint c = Convert.ToUInt32("FF", 16);
CallWhat it does
Convert.ToUInt32("4000000000")Large unsigned decimal string.
Convert.ToUInt32("FF", 16)Hex with base 16.

null → 0. Prefer uint.TryParse for untrusted text.

Library declarations
C#
public static uint ToUInt32(string? value);
public static uint ToUInt32(string? value, int fromBase);
public static uint ToUInt32(int value);

Parameters

ParameterDescription
valueRequired. Text or number to convert.
fromBaseOptional. 2, 8, 10, or 16.

Return Value

Return ValueDescription
uintUnsigned 32-bit result.

C# Examples

Example 1 — Bigger Than Int32

Parse an unsigned value above signed int max.

C#
using System;

class Program {
    static void Main() {
        uint n = Convert.ToUInt32("3000000000");
        Console.WriteLine(n);
        Console.WriteLine(n + 1);
    }
}

How It Works

  1. 3 billion. Above signed Int32 max.
  2. uint fits. Unsigned 32-bit can hold it.
  3. Increment. Shows normal arithmetic.
  4. No negatives. This type starts at zero.

Example 2 — Hex to UInt32

Parse a hex string into uint.

C#
using System;

class Program {
    static void Main() {
        uint n = Convert.ToUInt32("A0", 16);
        Console.WriteLine(n);
        Console.WriteLine(Convert.ToUInt32("1010", 2));
    }
}

How It Works

  1. A0 hex. Equals decimal 160.
  2. Binary 1010. Equals 10.
  3. fromBase. Chooses the digit system.
  4. Same API family. Matches other Convert base overloads.

Example 3 — Catch Negative Input

Demonstrate overflow on −1.

C#
using System;

class Program {
    static void Main() {
        try {
            Console.WriteLine(Convert.ToUInt32(-1));
        } catch (OverflowException) {
            Console.WriteLine("no negatives");
        }
        Console.WriteLine(Convert.ToUInt32(1));
    }
}

How It Works

  1. −1 rejected. Unsigned conversion overflows.
  2. Message path. Catch OverflowException.
  3. 1 succeeds. Positive values are fine.
  4. Use ToInt32. When signs are required.

Frequently Asked Questions

0 to 4,294,967,295.
Yes for typical ToUInt32 overloads.
No—they throw OverflowException.
Yes—2, 8, 10, or 16.
Parse throws on null; Convert returns 0.

Next: ToUInt64()

Convert a value to ulong for the largest unsigned whole numbers with System.Convert.

ToUInt64() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful