开发者

convert a single into 8 bytes invb.net

开发者 https://www.devze.com 2022-12-15 11:47 出处:网络
I have a single that might have a decimal place but might not. I have to put the digit before the decimal into the first 4 bytes and the digit after in the next 4 bytes.

I have a single that might have a decimal place but might not.

I have to put the digit before the decimal into the first 4 bytes and the digit after in the next 4 bytes.

So 1.1 would be 01-00-00-00-01-00-00-00

or 2.1 would be 02-00-00-00-01-00-00-00

or 1 would be 开发者_如何学JAVA01-00-00-00-00-00-00-00

The digit before the decimal point is stored like an integer in bytes the same with the digit after the point.

So 1.1 gets split into 1 and 1 and then stored as 2 DWORDS: 01000000 and 01000000


Like this:

Dim b(7) As Byte
b(0) = Convert.ToByte(Math.Floor(n))
b(4) = Convert.ToByte((n - Math.Floor(n)) * 10)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号