不能将'int'类型转换为'ushort':已经明确表达

Mic*_*ael 5 c# .net-micro-framework

我试图明确地将一个int转换成一个ushort,但是我得到的不能将'int'转换为'ushort'

ushort quotient = ((12 * (ushort)(channel)) / 16);
Run Code Online (Sandbox Code Playgroud)

我正在使用.Net Micro框架,因此BitConverter不可用.为什么我首先使用ushort与我的数据如何通过SPI发送有关.我可以理解这个特定的错误已经在这个网站上提出但我不明白为什么当我明确表示我不在乎是否有任何数据丢失,只需将32位切成16位我会很高兴.

            public void SetGreyscale(int channel, int percent)
    {
        // Calculate value in range of 0 through 4095 representing pwm greyscale data: refer to datasheet, 2^12 - 1
        ushort value = (ushort)System.Math.Ceiling((double)percent * 40.95);

        // determine the index position within GsData where our data starts
        ushort quotient = ((12 * (ushort)(channel)) / 16); // There is 12 peices of 16 bits
Run Code Online (Sandbox Code Playgroud)

我宁愿不改变int频道,也不想改变频道.我该如何解决错误?

Kin*_*ing 8

(ushort) channelushort,但12 * (ushort)(channel)int,而是执行此操作:

ushort quotient = (ushort) ((12 * channel) / 16);
Run Code Online (Sandbox Code Playgroud)