hey i would like to know how you could cast an Int array in C++ to an byte array and what would be the declaration method. I would appreciate if it is simpler and no use of pointers. thanks for the comments
Asked
Active
Viewed 1,040 times
-4
-
1Please, look at https://stackoverflow.com/help/how-to-ask and at https://stackoverflow.com/help/mcve first. – Daniel Langr Mar 29 '18 at 09:33
-
[Integer to byte Array conversion Code][1] [1]: https://stackoverflow.com/a/5585683/5250973 – Jay Dangar Mar 29 '18 at 09:35
-
1You will need to be more specific about your requirements. What do you envision the end result looking like? What have you tried so far? – Lightness Races in Orbit Mar 29 '18 at 09:44
1 Answers
1
This solution is a bit less convenient but maybe a bit more understandable from your perspective:
std::array<int, 3> arr_ints = {1, 2, 3};
std::array<unsigned char, 3> arr_bytes;
for(unsigned i=0; i<arr_ints.size(); ++i)
arr_bytes[i] = static_cast<unsigned char>(arr_ints[i]);

informant09
- 158
- 15
-
1`0 | arr_ints[i]`does not make much sense, does it? Is it intended to suppress a cast warning? Then a real cast would be much better. – user2328447 Mar 29 '18 at 09:43
-