forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3724c4
commit e55aa58
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2023 Intel Corporation. All Rights Reserved. | ||
|
||
#pragma once | ||
|
||
namespace rsutils | ||
{ | ||
namespace byte | ||
{ | ||
unsigned char reverse_bits(unsigned char b); | ||
void reverse_byte_array_bits(unsigned char* byte_array, int size); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2024 Intel Corporation. All Rights Reserved. | ||
|
||
#include <rsutils/byte-manipulation.h> | ||
|
||
namespace rsutils | ||
{ | ||
namespace byte | ||
{ | ||
// A helper function that takes a byte and reverses its bits | ||
// e.g. intput: 00110101 output: 10101100 | ||
|
||
// First the left four bits are swapped with the right four bits. | ||
// Then all adjacent pairs are swapped and then all adjacent single bits. | ||
// This results in a reversed order. | ||
unsigned char reverse_bits(unsigned char b) | ||
{ | ||
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; | ||
b = (b & 0xCC) >> 2 | (b & 0x33) << 2; | ||
b = (b & 0xAA) >> 1 | (b & 0x55) << 1; | ||
return b; | ||
} | ||
|
||
// A helper function that takes a byte rray of a given size, | ||
// and reverses the bits order of for each byte of this array | ||
// e.g. intput: byteArray = {byte0=00110101, byte1=11110000}, size = 2 | ||
// output: byteArray [ byte0=10101100, byte1=00001111] | ||
void reverse_byte_array_bits(unsigned char* byte_array, int size) { | ||
for (int i = 0; i < size; ++i) | ||
{ | ||
byte_array[i] = reverse_bits(byte_array[i]); | ||
} | ||
} | ||
} | ||
} | ||
|