简体   繁体   中英

convert byte array to uint numeric value

Let's say I have array of bytes

byte[] byteArr = new byte[] { 1, 2, 3, 4, 5 };

I want to convert this array to get regular numeric variable of uint, so result will be

uint result = 12345;

So far all the example I've seen were with bytes, byte I don't need bytes, but numeric value.

Thanks...

It sounds like you want something like:

uint result = 0;
foreach (var digit in array)
{
    result = result * 10 + digit;
}

Or more fancily, using LINQ:

uint result = array.Aggregate((uint) 0, (curr, digit) => curr * 10 + digit);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM