|
-
Apr 13th, 2009, 03:48 PM
#1
Thread Starter
Member
[RESOLVED] Increment byte[] by 0x01
I was wondering if anyone had simple/fast code for incrementing a byte[] by a single value. So for example:
Code:
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
becomes...
Code:
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
and...
Code:
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}
turns into...
Code:
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}
.
Thanks,
WB3000
-
Apr 13th, 2009, 04:02 PM
#2
Re: Increment byte[] by 0x01
Would this recursive function be good enough?
Code:
private void incrementAtIndex(byte[] array, int index) {
if (array[index] == byte.MaxValue) {
array[index] = 0;
if(index > 0)
incrementAtIndex(array, index - 1);
}
else {
array[index]++;
}
}
Call it by passing the array and the upper bound to it.
-
Apr 13th, 2009, 04:07 PM
#3
Thread Starter
Member
Re: Increment byte[] by 0x01
Seems to be working fine. Thanks a ton!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|