10-12-2017 06:57 PM - edited 10-12-2017 07:04 PM
@JÞB wrote:
@Borjomy wrote:
The meaning of the conversion is that the sum of the byte array will exceed the number 255, which is the maximum number for the byte. Therefore, the bit depth of the representation must be increased, at least up to U16. An array of constants in this case is used only to indicate the type to which the input data is converted. Therefore, its contents can be any.
Why? You immediately mask the most significant 24 bits anyhow!
Just let the rollover happen in the sum array elements and cast to string. (Unless you charge on a per-primitive basis, of course. Then its dandy!)
The number of bytes in the package is no more than 255. Therefore, U16 is sufficient. Even if all the bytes in the message are equal to 255, the maximum amount will be 0xFE01, which fits into the Word. But the example uses U32. For reliability 🙂
10-12-2017 07:41 PM
@Borjomy wrote:
@JÞB wrote:
@Borjomy wrote:
The meaning of the conversion is that the sum of the byte array will exceed the number 255, which is the maximum number for the byte. Therefore, the bit depth of the representation must be increased, at least up to U16. An array of constants in this case is used only to indicate the type to which the input data is converted. Therefore, its contents can be any.
Why? You immediately mask the most significant 24 bits anyhow!
Just let the rollover happen in the sum array elements and cast to string. (Unless you charge on a per-primitive basis, of course. Then its dandy!)
The number of bytes in the package is no more than 255. Therefore, U16 is sufficient. Even if all the bytes in the message are equal to 255, the maximum amount will be 0xFE01, which fits into the Word. But the example uses U32. For reliability 🙂
You missed the point. So, Lets "Do the math" In Hex if you please,
Word U16 (00FF*00FF) mod 0100 = 0001 Or
DWord U32 (000000FF*000000FF) mod 00000100 = 00000001
As Byte it is FF*FF=01
Simpler No?
10-13-2017 01:28 AM
@JÞB wrote:
@Borjomy wrote:
@JÞB wrote:
@Borjomy wrote:
The meaning of the conversion is that the sum of the byte array will exceed the number 255, which is the maximum number for the byte. Therefore, the bit depth of the representation must be increased, at least up to U16. An array of constants in this case is used only to indicate the type to which the input data is converted. Therefore, its contents can be any.
Why? You immediately mask the most significant 24 bits anyhow!
Just let the rollover happen in the sum array elements and cast to string. (Unless you charge on a per-primitive basis, of course. Then its dandy!)
The number of bytes in the package is no more than 255. Therefore, U16 is sufficient. Even if all the bytes in the message are equal to 255, the maximum amount will be 0xFE01, which fits into the Word. But the example uses U32. For reliability 🙂
You missed the point. So, Lets "Do the math" In Hex if you please,
Word U16 (00FF*00FF) mod 0100 = 0001 Or
DWord U32 (000000FF*000000FF) mod 00000100 = 00000001As Byte it is FF*FF=01
Simpler No?
You can do without type conversions