Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how i can convert int[] argb to byte[] argb ?
Posted

You can use:
C#
byte[] BitConverter.GetBytes(int)


Using LINQ extensions:
C#
int[] input;
byte[] output = input.SelectMany(i => BitConverter.GetBytes(i)).ToArray();
 
Share this answer
 
v3
Comments
Hala1990 24-Sep-12 6:59am    
but this int is array or not ?
sjelen 24-Sep-12 8:01am    
It's a single int.
Just put it in a loop...
Or combine it with Solution 2
Or take a look at updated solution.
Hey there,

Have you been at least Googling to see the size of an integer in C#? An integer is a signed 32-bit value. In other words, 1 int = 4 bytes.
C#
int[] data = {123, 321423,3950024, 2385704, 9759023,48634, 987653,6456895,46985589};
byte[] result = Array.ConvertAll(data, intValue => Convert.ToByte(intValue));

Of course, you can tweak this line of code if you are using C#3.5 or above.

But one important thing to note is that, Convert.ToByte method converts a 32-bit integer to an 8-bit integer, and I hope I don't need to point out what that would result.

Hope this helps, regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900