O
O
Oleg Seledets2018-07-09 18:03:25
C++ / C#
Oleg Seledets, 2018-07-09 18:03:25

How to split a binary string of numbers from a file and convert to Hex?

Hello, there is a file, it contains N number of lines. Each line has a maximum of 250 characters. zeros and ones, no spaces.
It is necessary to extract this string, after which, from its end, translate 4 characters into hexadecimal system.
Example:

100 4
00001  01
011101001010110110000001000 3A56C08

As I understand it, I create a stream through ifstream, get the value into a char variable of size 250, and then it’s more convenient to send it to a function, where the received value must be divided into 4-digit ones, and then after separating the first four, send it to the function with translation in hexadecimal? How can I separate 4 characters from the end?
------------
UPD
Divided the string, now I get the buff2 variable;
which now, for example, contains 0100.
How can you extract it in binary form?
Required from such a string to one binary value. get HEXIC.
usage
int buff4int = stoi(buff2);
cout << hex << buff4int << endl;

doesn't help because it translates from decimal.
in the answer, 100 is not 4, but 64.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
#
#, 2018-07-09
@oleja1ee7

pluses are not my forte.... you don't want to expand your erudition, in another language (with me it means c #) - yes, this will not be a direct solution... but at least it will be "food for thought";))
ps if it is interesting to tumble into the very essence - welcome to the comments

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question