1
我需要通過網絡發送一個從C#到Python的整數,它打擊了我,如果兩個語言的「規則」相同,並且它們的字節大小相同,應該是緩衝區大小,我可以int(val)
在Python中......我不能嗎?C#和Python中的int是一樣的嗎?
雙方都有大小爲32位,所以在Python和C#我應該能夠設置
C#:
String str = ((int)(RobotCommands.standstill | RobotCommands.turncenter)).ToString();
Stream stream = client.GetStream();
ASCIIEncoding asen = new ASCIIEncoding();
byte[] ba = asen.GetBytes(str);
stream.Write(ba, 0, 32);
的Python:
while True:
data = int(conn.recv(32));
print "received data:", data
if((data & 0x8) == 0x8):
print("STANDSTILL");
if((data & 0x20) == 0x20):
print("MOVEBACKWARDS");
爲什麼不試試看看會發生什麼? – 2012-08-05 13:06:08
@MichaelMauderer可能會出現一些不明確的情況,它會出錯。我問這個問題沒有問題。 – 2012-08-05 13:07:08
您的C#代碼是否運行?你聲稱你的int的字符串表示有32個字節,這顯然沒有。 – CodesInChaos 2012-08-05 13:10:03