---
title: "BitConvertor Class in C#"  
description: "In this blog I am trying to explain the concept of BitConvertor Class using C#.BitConvertor ClassThe BitConverter class helps manipulate value types i"  
author: "Vijay Shukla"  
published: 2013-06-17  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/541/bitconvertor-class-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# BitConvertor Class in C#

In this blog I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to [explain the concept](https://www.mindstick.com/forum/159605/explain-the-concept-of-unique-key-violation-error) of BitConvertor Class using C#.

BitConvertor Class

The BitConverter class helps manipulate value types in their fundamental form, as a [series](https://answers.mindstick.com/qa/101432/what-s-the-highest-score-in-a-single-world-series-game) of bytes. A byte is defined as an 8-bit unsigned integer. The BitConverter class includes [static methods](https://www.mindstick.com/forum/161339/static-methods-in-python) to [convert](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) each of the primitive types to and from an array of bytes, as the following table illustrates.

##### Note: -

If you use BitConverter methods to round-trip data, make sure that the GetBytes overload and the ToType [method](https://www.mindstick.com/forum/166/webservice-method) specify the same type. As the following example illustrates.

##### Example: -

```
using System;
public class Example{    public static void Main()    {        int value = -16;        Byte[] bytes = BitConverter.GetBytes(value);        // Convert bytes back to Int32.        int intValue = BitConverter.ToInt32(bytes, 0);
        Console.WriteLine("{0} = {1}: {2}",                          value, intValue,                          value.Equals(intValue) ? "Round-trips" : "Does not round-trip");
        // Convert bytes to UInt32.        uint uintValue = BitConverter.ToUInt32(bytes, 0);        Console.WriteLine("{0} = {1}: {2}", value, uintValue,                          value.Equals(uintValue) ? "Round-trips" : "Does not round-trip");
        Console.ReadKey();
    }
}
```

##### Output: -

![BitConvertor Class in C#](https://www.mindstick.com/blogs/57ff09cc-69d8-4220-ae60-ca9b22d7c1a7/images/932961ff-c386-4fcb-b5ff-148658d3750a.png)

---

Original Source: https://www.mindstick.com/blog/541/bitconvertor-class-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
