C++ Hex String To Byte Array

Net C# code snippet convert external file to byte array. Convert Int To. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. We need to prepare hex string before could convert hex to a byte array and vice versa, and I noticed many forum create a small function to do the conversion from string to hex and convert a string to byte. Convert from a hex string to a byte array in C# Feb 08, 2012 03:09 AM | dc2000 | LINK I was wondering if there's an easy way to convert from a string composed of hex bytes to a byte array?. Line 9 : char타입의 포인터를 byte 타입으로 변환합니다. What you are attempting to do is a conversion of hex string to byte. hexlify (data [, sep [, bytes_per_sep=1]]) ¶ Return the hexadecimal representation of the binary data. Since an ArrayBuffer is, in fact, a byte array, this conversion requires that both ends agree on how to represent the characters in the String as bytes. : char buf[] = "9EF4BCDE"; to an array of Hexidecimal bytes, equivalent to say: char buf[] = "\x9e\xf4\xbc\xde"; Ideas would be appreciated. The output of to_byte_string must be std::string. https://www. Hex Literals. However, it means that conversion to these types from std::string or from arrays of bytes is a slow and often a lossy operation, dependent on the "locale", and can throw exceptions. Lets say I have a string like "E00200BA9EFC00AC", how can I convert. i have a simple question: I want to define a hex character array in C, but I don't want to have to define the elements one at a time. Then, inside the try block, we read all the bytes from the given pth using readAllBytes() method. String Literals. org, a friendly and active Linux Community. Since the bytes type supports the buffer interface, the existing binary I/O operations in Python 2. The BitConverter class has a static overloaded GetBytes method that takes an integer, double or other base type value and convert that to a array of bytes. Converting hexadecimal values to varbinary and vice versa is now easier using the XQuery functionality available from SQL Server 2005. You may have to register or Login before you can post: click the register link above to proceed. Then, call BitConverter. I could do it in C but in Qt I did not find any solution :). For example, programmers can convert an image into a byte array and then convert the array to a string, thus converting an image to a string. High performance C# byte array to hex string to byte array. Example: hexstring. https://www. Assigning to and from a string: A ShortString is a fixed 255 characters. Like a byte is a group of 8 bits, a buffer is a group of a pre-defined number of bytes. Encode a byte array into a hex byte array (without whitespace). The result buffer is null-terminated. @mik-T, a hex string is in some format like 219098C10D7 which every two character converts to one single byte. A String can be converted to Byte Array in few different ways. the parseInt method with radix 16. Java Program to Convert File to byte array and Vice-Versa In this program, you'll learn to convert a File object to byte[] and vice-versa in Java. - NCodeGroup/NCode. 23: We pass hex_file_to_array a file pointer and pointer to an an array. Also, like the containers, these classes use implicit sharing as a memory and speed optimization. hexadecimal string to byte array in python I have a long Hex string that represents a series of values of different types. Furthermore, the only way to change the contents of an array in C is to make changes to each element in the array. High performance C# byte array to hex string to byte array. This should be at least not-worse than your version for small strings - there's no opportunity for the compiler to make a sub-optimal inlining decision on the string stream operators in particular, and (named) RVO will take care of eliding the copy from the return value to the caller's std::string hex. * * @param bytes A Byte array * @return A String representation */ public static String toHexString ( byte [] bytes ) { StringBuffer sb = new StringBuffer ( bytes. Having searched internet I didn't find a reliable converter. Length Dim hexArray(count - 1) As String For idx As Integer = 0 To count - 1 hexArray(idx) = ascii(idx). Below is a sample code snippet demonstrating the conversion of Byte Array to string in C#. How to: Convert char * String to System::Byte Array. And at end of line or end of buffer it will print a newline. Exception: This method throws ArgumentNullException if the byte array or you can say value is null. Parameters: str - a String to convert, may be null. Convert byte[ ] array to String: 8. Another way might be to use memset() to set the whole string to zeros. In big endian , the most significant byte is stored at the memory location with the lowest address (big byte first). I thought about a for-statement to store every single letter in a string array. When creating a Buffer from a string, this encoding will also correctly accept "URL and Filename Safe Alphabet" as specified in RFC 4648, Section 5. Before we convert a file to byte array and vice-versa, we assume we have a file named test. Application BrowseForFolder/Open Array(el1,el2,el3) Add values to an Array variable Arguments Command line arguments Asc(String) Return ASCII code for string AscB(String) Return the byte code for a character AscW(String) Return Unicode code for string. Convert a hexadecimal string to a byte array : HEX « Data Types « C# / C Sharp. The new buffer will be backed by the given byte array; that is, modifications to the buffer will cause the array to be modified and vice versa. We can use the array access notation to get a specific character from the string. Eventually, I got round to putting the functions in a module so I wouldn't keep cut and pasting them :). We often need to convert byte arrays to Hex String in Java, In order to print byte array contents in a readable format. I recently ran into a problem that requires me to work with hexadecimal strings and wanted to learn how the encoding/decoding process works. Convert Hexadecimal value String to ASCII value String. To convert a string into a. But this won't allow strings, as far as I know it can only be a byte array. Konvertera hex till text och hex avkoda strängar. I wish to convert this Hex String into a byte array so that I can shift each value out and convert it into its proper data type. In this post, we will discuss how to convert InputStream to byte array in Java. I want to define a hex character array in C, but I don't want to have to define the elements one at a time. Hex value to Binary: 16. memorystream object to hold the decompressed file. The code uses the string class's Replace method to replace the hyphens with the desired separator character. C Program to Generate Random Hexadecimal Bytes. Strings, Byte Arrays, and Variants. But if you don't need to use the data as a string, i. In this tutorial, we will show you how to convert hex to a byte array and vice verse in vb. The GetString is an extension that converts byte array to hex string, but my implicit conversion is failing. It converts the value to a null-terminated string with a specified base. Here's an alternate answer where I assume that you want a string of the actual bytes the pointer is pointing to. In fact, it can be done in a single line. Linq; namespace AbundantCode { internal class Program { //How to Convert Byte Array to String in C# ? private static void Main(string[] args) […]. It’s fairly easy to convert a C# String to a Stream and vice-versa. I need help converting the array into a hex value. From hex string s of 2n digits, build the equivalent array a of n bytes. The returned bytes object is therefore twice as long as the length of data. I am rather new to C++ and have came up empty on google. [NoBrainer] Convert byte array to hex string in PowerShell 2013-11-16 by Ronald Rink 2 Comments This is a rather quick one and I am merely writing it down as I tend to forget …. DA: 32 PA: 72 MOZ Rank: 27 [NoBrainer] ‘The Should command may only be used inside a. Some of these methods are ToDouble, ToChart, ToBoolean, ToInt16, and ToSingle. »UT 10: Hex string to hex array. pdf), Text File (. Language: ANSI C So I was wondering if any of you have any ideas as to a good way to go about converting a string of ASCII representations of a HEX byte string e. In the example that follows, we will then convert that byte array back to a string, effectively showing you how to do the conversion both ways. Net C# code snippet convert external file to byte array. Is there a routine in c# that will transform a string ie"Hello Mom" into a Byte[] array. ''' byte array to convert ''' a hex string Public Function ByteArrayToHex(ByVal comByte As Byte()) As String 'create a new StringBuilder object Dim builder As New StringBuilder(comByte. How to Convert Hexadecimal String to Byte Array in C# We can convert a character to byte in C#, we can also convert a string to byte array using Encoding. Can you convert a HEX byte to a literal character array? Dec 26, 2012, 08:38 am Ok, here's my problem - I have a byte array and i need to pull out the values but i want their hexidecimal values as a char array - can this be done?. Function HexSIDToDec Converts most hex SID values to decimal format. Convert hexadecimal String to Byte Array [VB. Substring(i, 2), 16); return bytes; }. String address = "28 A8 FB 13 5 0 0 0 B0"; 1. Characters from the array are written up to (but not including) a terminating null byte ('\0'); if a precision is specified, no more than the number specified are written. > is this serial permanent or it changes after installing OS or after changing partition format? The serial number of the physical disk drive is allocated by the manufacturer of the device. C Program to Generate Random Hexadecimal Bytes. - He shined his shoes. In order to convert a byte array to a Hex String are used: an array of 16 hexadecimal symbols (from 0 to 9,A,B,C,D,E,F);. getBytes()- Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array. Lets say I have a string like "E00200BA9EFC00AC", how can I convert. Below is a sample code snippet demonstrating the conversion of string to Byte Array in C#. - int x = 0x20; int y = 32; int z = 040; x == y == z To the compiler, these three variables contain the exact same value. Line 7 : 각 Mac string 값을 char타입의 포인터로 저장합니다. The intention for providing this code is to create a natural flow from C to MIPS, and to demonstrate how arrays in C and arrays in MIPS need not be thought of as radically different entities. Convert a hexadecimal string to a float. I have found char[] cTmp = pString. The output of to_byte_string must be std::string. Browse code - Windows Hex string <--> byte array converter (CSHexStringByteArrayConverter) sample in C# for Visual Studio 2008. These represent characters in ASCII. This should be at least not-worse than your version for small strings - there's no opportunity for the compiler to make a sub-optimal inlining decision on the string stream operators in particular, and (named) RVO will take care of eliding the copy from the return value to the caller's std::string hex. How to convert a hex string into a BYTE array? If this is your first visit, be sure to check out the FAQ by clicking the link above. Do you mean that you want an array of bytes (chars or ints?) with the numeric equivalent of each character from the string? e. This function reads the hex file, parses it, extracting the data and placing them into the the uint8_t array based on the data's address found in the hexfile. Convert String to ByteArray. str() function std::string conversion = buffer. You can either write your own method, or you can use open source library e. Converting a hex string to a byte array 17 answers I am searching the method to convert hex string into byte string in C++. You are currently viewing LQ as a guest. Please comment if you can see any optimizations that I can apply. Min and Max values of datatype int: 9. NOTE: This function will allocate the memory needed to store the encoded data. However, to handle words and sentences and screen labels and so on, strings are used. Some of them didn't look to clean. The same method converts byte array to hex string. 가시 :: [Delphi] Ansi String <-> Hex <-> Byte Array 함수. Therefore, arrays in C may be regarded as collections of like variables. High performance C# byte array to hex string to byte array. Now, how do we get a string value into this newly-allocated array? string. The expectation however is that binary I/O will read and write bytes, while text I/O will read strings. A humble request Our website is made possible by displaying online advertisements to our visitors. DA: 32 PA: 72 MOZ Rank: 27 [NoBrainer] ‘The Should command may only be used inside a. func (*Buffer) Grow ¶ 1. The function then returns the number of data bytes found in the hex file. My LCD screen outputs byte array strings… by program generates certain mode output that I want to feed to the LCD to update the screen…. The array has 256 elements. where each char element is stored in memory with a hex value. CString: A string data type. Net library to convert between byte arrays and strings using hex (base 16) encoding i. Likewise for Byte Array to Hex, it loop through the bytes and for each one converts them to a Hex representation. Append(Convert. On the ToBase64String, we have a bit of a challenge, since it expects a byte array and not a string to be passed in. The output of to_byte_string must be std::string. Home Community Categories Java How can I convert byte array into hex string in. We use getBytes, a method on the String class. eu/2011/08/22/how-to-convert-a-byte-array-to-a-hex-string-in-java/ Solutions and tutorials for IT&C development Sat, 14 Nov 2015 23:34:44. Parameters: str - a String to convert, may be null. How to Convert a Number to Bytes Array in C# ? Below is a sample code snippet demonstrating how to convert a Number to Byte Array in C#. i have converted strings to hexadecimal like this before (typing this from vague memory). Encoding is the process of transforming a set of Unicode characters into a sequence of bytes. I searched char* to hex string before but implementation I found adds some non-existent garbage at the end of hex string. However, it means that conversion to these types from std::string or from arrays of bytes is a slow and often a lossy operation, dependent on the "locale", and can throw exceptions. Endianess (or byte-order): For a multi-byte character, you need to take care of the order of the bytes in storage. One of the reasons hexadecimal is so nice is because 1 hexa digit is equal to a nibble or 4 bits, so if I were supposed to convert your string into a byte string it would have to be like: Code: A4 50 5D 0B 0F 6A ED AA 10100100 0101000 01011101 00001011 00001111 01101010 11101101 10101010. The new buffer will be backed by the given byte array; that is, modifications to the buffer will cause the array to be modified and vice versa. For that you have to determine if you are scanning left to right or right to left. Also: to convert from a stringstream back into a std::string, you can use the. Idiom #176 Hex string to byte array. What I mean by frame-of-reference, is that your common reference point between the input string, and the output array, is the last character, and the last member of the byte[] array. 'latin1' - A way of encoding the Buffer into a one-byte encoded string (as defined by the IANA in RFC 1345, page 63, to be the Latin-1 supplement block and C0/C1 control codes). Fundamentally, there are three operations which one can perform on an array:. We have stored some numeric elements in this byte array variable. The expectation however is that binary I/O will read and write bytes, while text I/O will read strings. To convert byte array to hex value, we loop through each byte in the array and use String 's format(). 在最近的项目中有用到plc与上位机通信的指令转换,用了各种方法,很是头疼,在网上搜集了和自己试着写了一下转换函数. Are you looking to compare two array of bytes in C#? Below is a sample code snippet that demonstrates how to do it. The code sample demonstrates how to convert a hex string to bytes and convert bytes to a hex string. In a hexadecimal string, one byte is represented two hexadecimal characters. Convert String to Byte Array - Free download as PDF File (. Now I need to copy this 498 bytes values to below array at a particular position starting from [4] to [498]. You need to first extract the two digit pairs from the string. String class has getBytes() method which can be used to convert String to byte array in Java. Line 9 : char타입의 포인터를 byte 타입으로 변환합니다. This function reads the hex file, parses it, extracting the data and placing them into the the uint8_t array based on the data's address found in the hexfile. That is the interface receives 8 bytes ( 0x51 0x74 0x43 0x65 0x6e 0x74 0x72 0x65 ) and you want to display the 16 character string "517443656e747265". A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. Probably to the fact that when converting to binary, the original text that was UTF16 was converted to ANSI. The way I am doing it now is to convert each byte into a two digit Hex pair for example, byArray(0) = 01 byArray(1) = 255 byArray(2) = 128 will be stored as a string of 01 FF 80. txt) or read online for free. using System; using System. Its obvious once you find it. If you had an array in which you stored decimal values and you converted these to their hex values and stored them in another array, both arrays would be identical. Convert byte[] array to File using Java To convert byte[] to file getBytes() method of String class is used, and simple write() method can be used to convert that byte into a file. For example, "6E-1D-9A-00". From hex string s of 2n digits, build the equivalent array a of n bytes. Text directive. For example, the byte data type requires 1 byte = 8 bits. But if you don't need to use the data as a string, i. As a result, I tend to write lots of helper methods that hide the stream manipulations so I don't have to remember them. ToString("X") ), it is not so easy to convert a hexadecimal string back into a byte array. The same method converts byte array to hex string. We use getBytes, a method on the String class. Convert a Generic List to a DataTable Using Reflection How to convert a generic List > to a DataTable with reflection. How to convert a byte array to a string in C#. This function can help make your geeky debugging sessions much happier. Yes it is easy and trivial but really I need help. In other words, at. However when i try to re-covert the byte array key to a hex-string only 8 bytes are printed instead of 16. Length; byte[] bytes = new byte[NumberChars / 2]; for (int i = 0; i < NumberChars; i += 2) bytes[i / 2] = Convert. However how do we convert a Byte[] array to String afterward? Simple toString() function like following code is not working property. Home; Convert a hex string into a byte array with one byte for every 2 hex characters. The join function allows to join the hexadecimal result into a string. str() function std::string conversion = buffer. /** * Return a hex-dump formatted version of a byte array. This post assumes that the datatype unsigned long int uses 4 bytes of internal storage; however the examples can easily be adapted to other built-in datatypes (unsigned short int, unsigned long long int, etc). Hex Literals. if a user enter 7700, my code is supposed to convert it to a string of hex i. The implementation makes use of an efficient table lookup that is approx 16x faster than using System. C/C++ function to Convert Hex String to Decimal Number May 7, 2014 No Comments c / c++ , code , code library , programming languages , tricks In C/C++ header file stdlib. The format function converts the bytes in hexadecimal format. 718281828459045 rounds to 2. If I understand correctly you have a byte array containing non-ascii values e. In C and C++, the distinction between a string and an array of bytes is often blurred. Zwei Methoden mit denen man einen String in ein Byte Array und ein Bytearray in einen String wandeln kann. You should line up your reference points, and work out from there. C# Code Snippet: Creating an md5 hash string. Free Download ×. In c++, BYTE is an unsigned char and a string is a char array. byte is 8 bit signed type ranges from –128 to 127. 6 will support bytes objects. VS 2012 [RESOLVED] String Array to Byte Array conversion If this is your first visit, be sure to check out the FAQ by clicking the link above. The following shows a implementation of such methods. Please help me TIA :) Example: The output must be like this. In MySQL blob has a method: getBytes() This method Retrieves all or part of the BLOB value that this Blob object represents, as an array of bytes. We can use the array access notation to get a specific character from the string. input string: shex = "00010A" return: array of bytes 0,1,10 see also:String date conversion. hexadecimal string to byte array in python I have a long Hex string that represents a series of values of different types. One of the reasons hexadecimal is so nice is because 1 hexa digit is equal to a nibble or 4 bits, so if I were supposed to convert your string into a byte string it would have to be like: Code: A4 50 5D 0B 0F 6A ED AA 10100100 0101000 01011101 00001011 00001111 01101010 11101101 10101010. By using this site,. byte literals are usually padded out to 2 digits, e. Generic; using […]. Using a bunch of help from posts on SO I was able to cob. The index to the last value in the array is the array size minus one. Zwei Methoden mit denen man einen String in ein Byte Array und ein Bytearray in einen String wandeln kann. ToString(byteArray). Every line will contain bytes_per_line bytes, each byte is represented using uppercase two digit hex. - C CONVERT HEX STRING TO. Convert a Generic List to a DataTable Using Reflection How to convert a generic List > to a DataTable with reflection. my_byte_array is a byte array variable. I have a string address included hex-values. DA: 32 PA: 72 MOZ Rank: 27 [NoBrainer] ‘The Should command may only be used inside a. [ RANDOM_BYTES=: 6 [email protected]:# 2 ^ 8 228 227 183 255 122 242 NB. ToString(), 16), 2). txt in our src folder. wrapper 가. And: Optimized C++ code is normally faster than doing the same thing in managed code, which has to check array bounds. Solo te toma un minuto registrarte. Example 1: Convert File to byte[] When you run the program, the output will be: In the above program, we store the path to the file in the variable path. The index is counted from zero. pdf), Text File (. Hello, I'm trying to make a powershell function to read a. I am looking for a fastest way to convert a byte array of arbitrary length to a hexadecimal string. NOTE: This function will allocate the memory needed to store the encoded data. The implementation makes use of an efficient table lookup that is approx 16x faster than using System. Yes it is easy and trivial but really I need help. It's a nul-terminated array of chars. I Prepared a hex string from the Byte[] array and using it in the query. Please add the using System. less than 1 minute read Find the bug in the following code and win a prize. I found this question by Googling for the same thing. Online tool for hex decoding a string. I want to convert s1 into s2 like below pseudo code. The second thing is the type of the output array. How to convert byte array to hex string in Java 1. CString: A string data type. 'latin1' - A way of encoding the Buffer into a one-byte encoded string (as defined by the IANA in RFC 1345, page 63, to be the Latin-1 supplement block and C0/C1 control codes). We're using PIC18F25J50 with XC8 compiler, The XC8 compiler supports for max long integer is 32 bits. The array may be built of either signed or unsigned characters. I do have a string variable that stores only a long number, which I have to convert to it's hexadecimal value and store it in another string variable. Its obvious once you find it. Set objUser = GetObject("LDAP://cn=Test User,ou=West,dc=MyDomain,dc=com") ' Retrieve the value of the objectGUID attribute as a byte array. Echo "OctetToHexStr(objUser. Line 7 : String. In all cases, the conversion begins in initial shift state, unless non-initial starting state was provided to this wstring_convert constructor. You may have to register or Login before you can post: click the register link above to proceed. Lets say I have a string like "E00200BA9EFC00AC", how can I convert. Look at what lengths people have gone to to solve this problem for them: How do you convert Byte Array to Hexadecima. wrapper 가. GetBytes(asciiString) Dim count As Integer = ascii. Another way might be to use memset() to set the whole string to zeros. The index to the last value in the array is the array size minus one. Convert byte[] array to File using Java To convert byte[] to file getBytes() method of String class is used, and simple write() method can be used to convert that byte into a file. Cap returns the capacity of the buffer's underlying byte slice, that is, the total space allocated for the buffer's data. NET Framework functions. Zwei Methoden mit denen man einen String in ein Byte Array und ein Bytearray in einen String wandeln kann. In the above program, we have a byte array named bytes. The easiest Hex string to/from byte array I've found When looking for a utility function to convert from a hex string to a byte array, I found this example. SHA-1 hash considered to be one of the most secure hashing functions, producing a 160-bit digest (40 hex numbers) from any data with a maximum size of 264 bits. encoding (Optional) - if source is a string, the encoding of the string. NET Core C# • C# UWP/WinRT • DataFlex • Delphi ActiveX • Delphi DLL • Visual FoxPro • Java • Lianja • MFC • Objective-C • Perl • PHP ActiveX • PHP Extension • PowerBuilder • PowerShell • PureBasic • CkPython • Chilkat2-Python. :) toCharArray копирует в буфер строку вместе с завершающим нулём, значит для нуля нужно тоже выделить место. Another way might be to use memset() to set the whole string to zeros. if pFile is a CFile* and m_pFileData is BYTE[ /*length of document*/] then pFile->Read (m_pFileData, /*length of document*/); the BYTE array is filled in such a way that BYTE b[] filled by calling. Such a function is useful when you need to backup data from your application on paper, such as an. Result MUST be released using jw_data_free. For example, the character array {' \x63 ', ' \x61 ', ' \x74 ', ' \0 '} is an NTBS holding the string "cat" in ASCII encoding. String 타입의 변수 hexString에 16진수 문자열 01020304FF11을 대입합니다. We use cookies for various purposes including analytics. Net, every string has a character set and encoding. Image to Byte array Use this online image to Byte array tool for converting (monochromatic) bitmaps to data arrays (C++ style). This library provides the Data. Character data is subject to interpretation. We use %02X to print two places ( 02 ) of Hexadecimal ( X ) value and store it in the string st. Chilkat • HOME • Android™ • Classic ASP • C • C++ • C# • Mono C# •. String Literals. Memory usage. The easiest Hex string to/from byte array I've found When looking for a utility function to convert from a hex string to a byte array, I found this example. It's the same solution as Sparr did but instead of HEX you expected int presentation (range from 0 to 255) of each char. i used a script to generate 0x00 thru 0xff and used a lookup table to convert a string of hex values (e. Integer array for accessing the string data (1 character = 2 bytes = Integer) and a Long array for memory manipulation (PutMem4 & GetMem4 replacement) as well as saving the decoded hex string to the byte array. The BitConverter class in. The values in the BYTE array represent hex characters for a file read in binary form. The other user input value is for a variable kV which is converted into hex after user provide it; e. This code will work in situations where you are not aware of the encoding type used and the system will pick the default encoding as specified in the system file encoding property. the parseInt method with radix 16. This answer is basically the same as in the question In Java, how do I convert a byte array to a string of hex digits while keeping leading zeros?. Java byte: byte is smallest Java integer type. // Convert Hex String to Byte Array. How to convert "string" into "byte array" and vice versa? Play with image A Technique in Java - Search image, Convert image to text , Hide data; Convert char array To byte array; Byte string to Unicode & vice versa; Convert bit string to byte; Class property as a Byte array; How to convert DataTable to Base64?. This is a custom CFML tag which will return a pattern matched string to an array, with each backreference occupying an element of the array and the whole matched string occupying the first element. It does not have symbols like 10 or 11, so it take letters as symbol from English alphabet. Using a bunch of help from posts on SO I was able to cob. Online verktyg för hex avkodning en sträng. We're using PIC18F25J50 with XC8 compiler, The XC8 compiler supports for max long integer is 32 bits. Introduction Conversion of bytes to hex string and vice versa is a common task with a variety of implementations. ToString method in the. To convert hexadecimal to binary in Java Programming, you have to ask to the user to enter any number in hexadecimal number format to convert it into binary number format to display the equivalent value in binary number system as shown in the following program. In this tutorial, we will show you how to convert hex to a byte array and vice verse in vb. QString, QByteArray, and QVariant are three classes that have many things in common with containers and that can be used as alternatives to containers in some contexts. Question: How can I split it to char array? And char-values to Byte-array?. With 8 bits converted to three characters and each character stored as 1-4 bytes you might use up to 12 bytes (or even more in some cases) for each byte of information. This should be at least not-worse than your version for small strings - there's no opportunity for the compiler to make a sub-optimal inlining decision on the string stream operators in particular, and (named) RVO will take care of eliding the copy from the return value to the caller's std::string hex.