निर्दिष्ट दशमलव के मान को समतुल्य 16-बिट अहस्ताक्षरित पूर्णांक में बदलने के लिए, कोड इस प्रकार है -
उदाहरण
using System;
public class Demo {
public static void Main() {
Decimal val = 875.647m;
Console.WriteLine("Decimal value = "+val);
ushort res = Decimal.ToUInt16(val);
Console.WriteLine("16-bit unsigned integer = "+res);
}
} आउटपुट
यह निम्नलिखित आउटपुट देगा -
Decimal value = 875.647 16-bit unsigned integer = 875
उदाहरण
आइए एक और उदाहरण देखें -
using System;
public class Demo {
public static void Main() {
Decimal val = 0.001m;
Console.WriteLine("Decimal value = "+val);
ushort res = Decimal.ToUInt16(val);
Console.WriteLine("16-bit unsigned integer = "+res);
}
} आउटपुट
यह निम्नलिखित आउटपुट देगा -
Decimal value = 0.001 16-bit unsigned integer = 0