Decimal Implicit Conversion (SByte to Decimal)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Converts an 8-bit signed integer to a Decimal.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
- Type: System.SByte
An 8-bit signed integer.
The following code example converts SByte values to Decimal numbers using the SByte to Decimal conversion. This conversion is implicit in C#, but requires the op_Implicit operator in Visual Basic and C++. Implicit conversions to Decimal use other methods in these languages.
// Example of the implicit conversion from sbyte to decimal. using System; class Example { const string formatter = "{0,15}{1,15}{2,10:X8}{3,9:X8}{4,9:X8}{5,9:X8}"; // Convert the sbyte argument and display the decimal value. public static void DecimalFromSByte(System.Windows.Controls.TextBlock outputBlock, sbyte argument) { decimal decValue; int[] bits; // Display the decimal and its binary representation. decValue = argument; bits = decimal.GetBits(decValue); outputBlock.Text += String.Format(formatter, argument, decValue, bits[3], bits[2], bits[1], bits[0]) + "\n"; } public static void Demo(System.Windows.Controls.TextBlock outputBlock) { outputBlock.Text += String.Format( "This example of the implicit conversion from sbyte " + "to decimal generates the \nfollowing output. It " + "displays the decimal value and its binary " + "representation.\n") + "\n"; outputBlock.Text += String.Format(formatter, "sbyte argument", "decimal value", "bits[3]", "bits[2]", "bits[1]", "bits[0]") + "\n"; outputBlock.Text += String.Format(formatter, "--------------", "-------------", "-------", "-------", "-------", "-------") + "\n"; // Convert sbyte values and display the results. DecimalFromSByte(outputBlock, sbyte.MinValue); DecimalFromSByte(outputBlock, sbyte.MaxValue); DecimalFromSByte(outputBlock, 0x3F); DecimalFromSByte(outputBlock, 123); DecimalFromSByte(outputBlock, -100); } } /* This example of the implicit conversion from sbyte to decimal generates the following output. It displays the decimal value and its binary representation. sbyte argument decimal value bits[3] bits[2] bits[1] bits[0] -------------- ------------- ------- ------- ------- ------- -128 -128 80000000 00000000 00000000 00000080 127 127 00000000 00000000 00000000 0000007F 63 63 00000000 00000000 00000000 0000003F 123 123 00000000 00000000 00000000 0000007B -100 -100 80000000 00000000 00000000 00000064 */
Show: