首页 > 解决方案 > arduino vb.net 溢出 ASCII 和

问题描述

我遇到了这个问题:算术溢出操作

请问有什么问题,非常感谢

'I will read 999 ASCII chars from the serial buffer
'999 char * 255 max value of ASCII = 254,745 
'For 254,745 I will need Long to handle this size
'I used Long to handle the big sum of the received data so I will not get
'summation overflow

Dim int_sum_of_packet As Long = 0

'I took the data from serial buffer and saved it into string
'string name is = str_packet_data_without_delimiter

'Get each char inside the received string
For Each ch As Char In str_packet_data_without_delimiter
    'do the summation
    int_sum_of_packet = int_sum_of_packet + Convert.ToByte(ch)
Next

'Now get the LSB (least significant Byte)
'Note: Long data type is 8 Bytes

Dim lsb As Byte
lsb = CByte(&H000000FF & int_sum_of_packet)

标签: vb.netarduino

解决方案


推荐阅读