He,
How to convert an Int32 or an Int to a byte (encoded 8 bytes) ?
for examle convert 2 (Int32) to a byte 00000001
Best regards
f
![]() |
0 |
![]() |
Friend, if you want to convert to a byte array, here is the code
Dim arr as byte()
arr = BitConverter.GetBytes(MyInt)Here MyInt is you Int32 variable
Else you can try this also
http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=788
Hope it helped you. Good luck!
Please Don't forget to click "Mark as Answer" on the post that helped you.
This can be beneficial to other community members reading the thread.
![]() |
0 |
![]() |
Convert.ToByte(12)
Convert.ToSomeType(value)
etc...
![]() |
0 |
![]() |
Hi,
The byte denotes an integral type that stores values (range from 0-255). Int value can be converted to byte explicitly. For more information, see http://msdn.microsoft.com/en-us/library/5bdb6693(VS.80).aspx
I guess you want to convert it to binary format. If so, we can use ToString method with second parameter with value 2, 8, 10 or 16 for binary, octal, decimal and hexadecimal, respectively. You can try the following code:
byte b = 255;
string s = Convert.ToString(b, 2);
s = String.Format("{0:000000000}", Convert.ToInt32(s));
Response.Write(s);
Response.Write("<br />");
int i = 1;
s = Convert.ToString(i, 2);
s = String.Format("{0:000000000}", Convert.ToInt32(s));
Response.Write(s);
I look forward to hearing from you.
Thomas Sun
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
![]() |
0 |
![]() |
He,
I I have two integers for example :
int i = 1;
si = Convert.ToString(i, 2);
si = String.Format("{0:000000000}", Convert.ToInt32(si));
Response.Write(s);and
int j = 4;
sj = Convert.ToString(j, 2);
sj = String.Format("{0:000000000}", Convert.ToInt32(sj));
Response.Write(s);How can we binary add(&) i and j : i&j ? si&sj does not work
Best regards
f
![]() |
0 |
![]() |
Hi,
We can convert these int values to byte values and then perform and (&) operation.
For instance:
string sR;
int i = 1, j = 4;
byte a = Convert.ToByte(i);
byte b = Convert.ToByte(j);
byte result = Convert.ToByte(a & b);
sR = Convert.ToString(result, 2);
sR = String.Format("{0:000000000}", Convert.ToInt32(sR));
Response.Write(sR);I look forward to hearing from you.
Thomas Sun
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
![]() |
0 |
![]() |