c#,java类型转换

 C#  变量转换

float.Parse(控件.Text.Trim());//控件变量转换浮点数
 str = Encoding.Unicode.GetString(sendbuf, 0, 48);//将数组转换为字符串
 byte[] highX3 = BitConverter.GetBytes(浮点型);//将浮点型转换成4个字节数

//将输入的字符串转换 为16进制数组
string tmp_b2 = Convert.ToString(textBox3.Text.ToString().Trim());
tmp_b2 = tmp_b2.Replace(" ","");//删除字符串中间的空格
 //将收到的字符串分成4个字节,这4个字节是字符串的形式
string tmp_char1 = tmp_b2.Substring(0,2);
string tmp_char2 = tmp_b2.Substring(2,2)

b2[3] = Convert.ToByte(tmp_char1, 16);
b2[2] = Convert.ToByte(tmp_char2, 16);
//将16进制byte转换成浮点数格式
 f2 = BitConverter.ToSingle(b2, 0);


 //将int型转换为数组
 byte[] sbuf = new byte[4];
int sleepTime   
buf[0] = (byte)(sleepTime & 0xff);
buf[1] = (byte)((sleepTime >> 8) & 0xff);
buf[2] = (byte)((sleepTime >> 16) & 0xff);
sbuf[3] = (byte)((sleepTime >> 24) & 0xff);

猜你喜欢

转载自blog.csdn.net/u010312937/article/details/100548618