[2c47b73] | 1 | /** |
---|
| 2 | * @file ByteToolkit.h |
---|
| 3 | * @author Sheng Di |
---|
| 4 | * @date July, 2017 |
---|
| 5 | * @brief Header file for the ByteToolkit.c. |
---|
| 6 | * (C) 2016 by Mathematics and Computer Science (MCS), Argonne National Laboratory. |
---|
| 7 | * See COPYRIGHT in top-level directory. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #ifndef _ByteToolkit_H |
---|
| 11 | #define _ByteToolkit_H |
---|
| 12 | |
---|
| 13 | #ifdef __cplusplus |
---|
| 14 | extern "C" { |
---|
| 15 | #endif |
---|
| 16 | |
---|
| 17 | #include <stdio.h> |
---|
| 18 | |
---|
| 19 | //ByteToolkit.c |
---|
| 20 | |
---|
| 21 | unsigned short bytesToUInt16_bigEndian(unsigned char* bytes); |
---|
| 22 | unsigned int bytesToUInt32_bigEndian(unsigned char* bytes); |
---|
| 23 | unsigned long bytesToUInt64_bigEndian(unsigned char* b); |
---|
| 24 | |
---|
| 25 | short bytesToInt16_bigEndian(unsigned char* bytes); |
---|
| 26 | int bytesToInt32_bigEndian(unsigned char* bytes); |
---|
| 27 | long bytesToInt64_bigEndian(unsigned char* b); |
---|
| 28 | int bytesToInt_bigEndian(unsigned char* bytes); |
---|
| 29 | |
---|
| 30 | void intToBytes_bigEndian(unsigned char *b, unsigned int num); |
---|
| 31 | |
---|
| 32 | void int64ToBytes_bigEndian(unsigned char *b, uint64_t num); |
---|
| 33 | void int32ToBytes_bigEndian(unsigned char *b, uint32_t num); |
---|
| 34 | void int16ToBytes_bigEndian(unsigned char *b, uint16_t num); |
---|
| 35 | |
---|
| 36 | long bytesToLong_bigEndian(unsigned char* b); |
---|
| 37 | void longToBytes_bigEndian(unsigned char *b, unsigned long num); |
---|
| 38 | long doubleToOSEndianLong(double value); |
---|
| 39 | int floatToOSEndianInt(float value); |
---|
| 40 | short getExponent_float(float value); |
---|
| 41 | short getPrecisionReqLength_float(float precision); |
---|
| 42 | short getExponent_double(double value); |
---|
| 43 | short getPrecisionReqLength_double(double precision); |
---|
| 44 | unsigned char numberOfLeadingZeros_Int(int i); |
---|
| 45 | unsigned char numberOfLeadingZeros_Long(long i); |
---|
| 46 | unsigned char getLeadingNumbers_Int(int v1, int v2); |
---|
| 47 | unsigned char getLeadingNumbers_Long(long v1, long v2); |
---|
| 48 | short bytesToShort(unsigned char* bytes); |
---|
| 49 | void shortToBytes(unsigned char* b, short value); |
---|
| 50 | int bytesToInt(unsigned char* bytes); |
---|
| 51 | long bytesToLong(unsigned char* bytes); |
---|
| 52 | float bytesToFloat(unsigned char* bytes); |
---|
| 53 | void floatToBytes(unsigned char *b, float num); |
---|
| 54 | double bytesToDouble(unsigned char* bytes); |
---|
| 55 | void doubleToBytes(unsigned char *b, double num); |
---|
| 56 | int extractBytes(unsigned char* byteArray, size_t k, int validLength); |
---|
| 57 | int getMaskRightCode(int m); |
---|
| 58 | int getLeftMovingCode(int kMod8); |
---|
| 59 | int getRightMovingSteps(int kMod8, int resiBitLength); |
---|
| 60 | int getRightMovingCode(int kMod8, int resiBitLength); |
---|
| 61 | short* convertByteDataToShortArray(unsigned char* bytes, size_t byteLength); |
---|
| 62 | unsigned short* convertByteDataToUShortArray(unsigned char* bytes, size_t byteLength); |
---|
| 63 | |
---|
| 64 | void convertShortArrayToBytes(short* states, size_t stateLength, unsigned char* bytes); |
---|
| 65 | void convertUShortArrayToBytes(unsigned short* states, size_t stateLength, unsigned char* bytes); |
---|
| 66 | void convertIntArrayToBytes(int* states, size_t stateLength, unsigned char* bytes); |
---|
| 67 | void convertUIntArrayToBytes(unsigned int* states, size_t stateLength, unsigned char* bytes); |
---|
| 68 | void convertLongArrayToBytes(int64_t* states, size_t stateLength, unsigned char* bytes); |
---|
| 69 | void convertULongArrayToBytes(uint64_t* states, size_t stateLength, unsigned char* bytes); |
---|
| 70 | |
---|
| 71 | size_t bytesToSize(unsigned char* bytes); |
---|
| 72 | void sizeToBytes(unsigned char* outBytes, size_t size); |
---|
| 73 | |
---|
| 74 | #ifdef __cplusplus |
---|
| 75 | } |
---|
| 76 | #endif |
---|
| 77 | |
---|
| 78 | #endif /* ----- #ifndef _ByteToolkit_H ----- */ |
---|
| 79 | |
---|