| 2787 | */ |
| 2788 | |
| 2789 | char *CPLBinaryToHex(int nBytes, const GByte *pabyData) |
| 2790 | |
| 2791 | { |
| 2792 | CPLAssert(nBytes >= 0); |
| 2793 | char *pszHex = static_cast<char *>( |
| 2794 | VSI_MALLOC_VERBOSE(static_cast<size_t>(nBytes) * 2 + 1)); |
| 2795 | if (!pszHex) |
| 2796 | { |
| 2797 | pszHex = CPLStrdup(""); |
| 2798 | return pszHex; |
| 2799 | } |
| 2800 | pszHex[nBytes * 2] = '\0'; |
| 2801 | |
| 2802 | constexpr char achHex[] = "0123456789ABCDEF"; |
| 2803 | |
| 2804 | for (size_t i = 0; i < static_cast<size_t>(nBytes); ++i) |
| 2805 | { |
| 2806 | const int nLow = pabyData[i] & 0x0f; |
| 2807 | const int nHigh = (pabyData[i] & 0xf0) >> 4; |
| 2808 | |
| 2809 | pszHex[i * 2] = achHex[nHigh]; |
| 2810 | pszHex[i * 2 + 1] = achHex[nLow]; |
| 2811 | } |
| 2812 | |
| 2813 | return pszHex; |
| 2814 | } |
| 2815 | |
| 2816 | /************************************************************************/ |
| 2817 | /* CPLHexToBinary() */ |
no test coverage detected