tcl中网络到主机地址的转换

tcl中网络到主机地址的转换,tcl,Tcl,在tcl中转换此代码,以及如何在tcl中创建到主机的功能网络 capturedTlpData[i] = (UInt32)IPAddress.NetworkToHostOrder(BitConverter.ToInt32((byte[])retValbuffer,i*4)); 此处NetworkToHostOrder为:- ` 您已经从网络中读取了四个字节的网络endian格式,是否要将其转换为无符号整数?二进制扫描命令可以做到这一点。您需要u修饰符,它需要tcl8.6 binary scan

在tcl中转换此代码,以及如何在tcl中创建到主机的功能网络

capturedTlpData[i] = (UInt32)IPAddress.NetworkToHostOrder(BitConverter.ToInt32((byte[])retValbuffer,i*4));
此处NetworkToHostOrder为:- `


您已经从网络中读取了四个字节的网络endian格式,是否要将其转换为无符号整数?
二进制扫描
命令可以做到这一点。您需要
u
修饰符,它需要tcl8.6

binary scan $theBytes Iu theValue
例如,如果您有与ASCII
abcd
对应的字节,则您会得到:

set theBytes "abcd"
binary scan $theBytes Iu theValue
puts $theValue
# Prints 1633837924
puts [format %x $theValue]
# Prints 61626364
如果您使用的是Tcl 8.5,只需使用
I
说明符,并使用此说明符对值进行后期处理,以将其转换为unsigned(因为Tcl在内部使用bignums):


快速回答请在tcl中通常不需要这样做,因为tcl接受网络地址作为点十进制字符串。你的用例是什么?那么我应该怎么做才能在tcl中做同样的事情呢?你能告诉我转换吗?通常没有转换。我不得不再次问,你的用例是什么?要将二进制32位整数保存到文件中还是通过网络发送?文本不够好有什么原因吗?换一种方式将使用
二进制格式
。“网络订购”是大端的。
set theBytes "abcd"
binary scan $theBytes Iu theValue
puts $theValue
# Prints 1633837924
puts [format %x $theValue]
# Prints 61626364
set theValue [expr {$theValue & 0xFFFFFFFF}]