I'm having a little trouble with converting arrays (i.e []u8, []int, etc.) into an int, in this case. I primarily come from a C#/Java and Some C/C++ background, so those languages had a lot of helper functions. I attempted to produce it manually by doing:
for i := len(array) - 1; i >= 0; i -= 1 {
val := val * 10 + array[i];
}
as well as the vice-versa:
for i := 0; i < len(array); i += 1 {
val := val * 10 + array[i];
}
but none of those produce what I'm looking for. For example, I have an array that has { 0x00, 0x1A, 0xFA, 0x00 } and I want to convert it to 0x001AFA00 or the reverse 0x00FA1A00, but instead I get results such as 0x00CBFC00 and so on.
Normally in C# or Java you would just use BitConverter.ToInt32(val) and when looking at the underlining code it's similar to this, so I'm not sure where I'm going wrong. I did look up some C99 examples and they're relatively similar, adding usage of sscanf or malloc.