Decimal.GetBits() Method in C#
Decimal.GetBits() Method is used to convert the value of a specified instance of Decimal to its equivalent binary representation.
Syntax: public static int[] GetBits (decimal d);
Here, it takes the floating point value to convert.Return Value: This method returns a 32-bit signed integer array with four elements that contain the binary representation of d.
Below programs illustrate the use of Decimal.GetBits() Method
Example 1:
// C# program to demonstrate the // Decimal.GetBits() Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { // Declaring and initializing value decimal value = 18446744073709551615M; // getting Equivalent bit // using GetBits() method int[] arr = Decimal.GetBits(value); // Display the element for (int i = 0; i < arr.Length; i++) Console.WriteLine("Bit[{0}] = {1, 10:X8}", i, arr[i]); } } |
Output:
Bit[0] = FFFFFFFF Bit[1] = FFFFFFFF Bit[2] = 00000000 Bit[3] = 00000000
Example 2:
// C# program to demonstrate the // Decimal.GetBits() Method using System; using System.Globalization; class GFG { // Main Method public static void Main() { // calling get() method get(Decimal.MaxValue); Console.WriteLine(""); get(Decimal.MinValue); } // defining get() method public static void get(decimal value) { // getting Equivalent bit // using GetBits() method Console.WriteLine("Converted value of {0} is", value); int[] arr = Decimal.GetBits(value); // Display the element for (int i = 0; i < arr.Length; i++) Console.WriteLine("Bit[{0}] = {1, 10:X8}", i, arr[i]); } } |
Output:
Converted value of 79228162514264337593543950335 is Bit[0] = FFFFFFFF Bit[1] = FFFFFFFF Bit[2] = FFFFFFFF Bit[3] = 00000000 Converted value of -79228162514264337593543950335 is Bit[0] = FFFFFFFF Bit[1] = FFFFFFFF Bit[2] = FFFFFFFF Bit[3] = 80000000
Reference:
Recommended Posts:
- Difference between Method Overriding and Method Hiding in C#
- C# | Random.Next() Method
- C# | Method Parameters
- C# | Math.Abs() Method | Set - 2
- C# | Method Overriding
- Main Method in C#
- Decimal.Add() Method in C#
- Method Hiding in C#
- C# | IsNullOrEmpty() Method
- Stack.Contains() Method in C#
- Stack.Pop() Method in C#
- C# | Uri.ToString() Method
- C# | Math.Exp() Method
- C# | Math.Abs() Method | Set - 1
- Queue.Contains() Method in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



