我正在尝试将 int 显式转换为 ushort 但无法将类型 'int' 隐式转换为 'ushort'
ushort quotient = ((12 * (ushort)(channel)) / 16);
我正在使用 .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
我不希望将 int 频道更改为 ushort 频道。我该如何解决这个错误?