M mei xiao Jul 8, 2004 #1 Hi, there, I want to change an integer into 4 bytes in c sharp, what should I do? Thank you. -May
S Shakir Hussain Jul 8, 2004 #2 Try this int myint = 2345; byte [] mybytes = new byte[4]; int i, shift; for(i = 0, shift = 24; i < 4; i++, shift -= 8) mybytes = (byte)(0xFF & (myint >> shift));
Try this int myint = 2345; byte [] mybytes = new byte[4]; int i, shift; for(i = 0, shift = 24; i < 4; i++, shift -= 8) mybytes = (byte)(0xFF & (myint >> shift));
M Mattias Sjögren Jul 8, 2004 #3 I want to change an integer into 4 bytes in c sharp, what should I do? Use the shift operators or the BitConverter class. Mattias
I want to change an integer into 4 bytes in c sharp, what should I do? Use the shift operators or the BitConverter class. Mattias
M mikeb Jul 8, 2004 #4 mei said: Hi, there, I want to change an integer into 4 bytes in c sharp, what should I do? Thank you. Click to expand... byte [] myBytes = BitConverter.GetBytes( myInt);
mei said: Hi, there, I want to change an integer into 4 bytes in c sharp, what should I do? Thank you. Click to expand... byte [] myBytes = BitConverter.GetBytes( myInt);
J Jon Skeet [C# MVP] Jul 8, 2004 #5 mei xiao said: I want to change an integer into 4 bytes in c sharp, what should I do? Thank you. Click to expand... See BitConverter.GetBytes(int)
mei xiao said: I want to change an integer into 4 bytes in c sharp, what should I do? Thank you. Click to expand... See BitConverter.GetBytes(int)