Get decimal value from Byte array

May 18, 2012 at 7:12pm
This one has me scratching my head, but I am sure I am overlooking something very simple.
I have a byte array 2048 long. It stores, obviously, ascii strings and it also stores decimal values in a single index.
byte inputBuff[2048];
at index 0 is a decimal value of 34.
How do I assign this decimal value to an int? Performing a cast does not work.
int b = (int)inputBuff[0]; as i get a value of 38179120

Any help is greatly appreciated.
May 18, 2012 at 10:38pm
Well, implicit casting works OK for me with what I thought could be your definition of byte (either char or unsigned char). See http://ideone.com/c2sB8 .
May 19, 2012 at 6:27am
It's dependant on how you've represented the decimals.

What do you mean by decimal?
May 19, 2012 at 1:47pm
Sorry for the delay..... This particular field is a length field represented by the value 34. that is the literal value and it is the length of a record. This is the only value stored this way. the others are an 4 byte length which are easy to convert to decimal. this is already decimal. let me know if that answers it.
May 19, 2012 at 2:53pm
Wait, you guys are right. The problem, which I just determined, is that I am passing an array pointer to a function and was accessing the data incorrectly. It is managed c++ (don't worry, I will rewrite it in native) so I won't post the code unless someone wants to see it.
Topic archived. No new replies allowed.