I have a binary data block(a byte), and I want to convert it to decimal. Is there any inbuilt function to do that.

Re: Function to convert a binary to decimal 80 80

All data are stored as binary. You can only change how it is displayed. If you only want to print the data as decimal, just use normal cout. If not, explain what you want to do with an example input and corresponding output.

Re: Function to convert a binary to decimal 80 80

Ok, first what I have done is read a binary file and count the number of bytes there. Then make groups of 20 bytes. From that I can find number of bits, multiplying by 8. I think it is ok.

This is the code use to count the bytes of the file.

long begin, end;
	ifstream filesize ("[I]path of the binary file[/I]");
	
	begin = filesize.tellg();
	filesize.seekg (0, ios::end);
	end = filesize.tellg();
	filesize.close();

	cout << "Size is " << (end - begin) << " bytes.\n";

Then what I want to do is such a small 20byte group should be display in decimal.

I think clear enough. So..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.