•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,531 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,890 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 26395 | Replies: 1
![]() |
•
•
Join Date: Aug 2003
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Hello,
I need to know how the get the integer value of a byte and vice versa.
I want to get the integer value from a byte read from a binary file.
I also want to convert the integer value back into a byte value for write.
Below I have code where the current byte is read into the variable 'byte". I am basically copying one file to the other.
Thanks.
I need to know how the get the integer value of a byte and vice versa.
I want to get the integer value from a byte read from a binary file.
I also want to convert the integer value back into a byte value for write.
Below I have code where the current byte is read into the variable 'byte". I am basically copying one file to the other.
Thanks.
#include <fstream.h>
#include <iomanip.h>
int main()
{
int ind, tot;
unsigned char byte;
ifstream infile("inputfile.dat", ios::in | ios::binary);
ofstream outfile("outputfile.dat", ios::binary );
for (!infile)
{
infile.read( byte, 1 );
outfile.write( byte, 1 );
return 0;
}
}•
•
Join Date: Sep 2003
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
#include <fstream.h>
#include <iomanip.h>
int main()
{
int ind, tot;
unsigned char byte;
ifstream infile("inputfile.dat", ios::in | ios::binary);
ofstream outfile("outputfile.dat", ios::binary );
for (!infile)
{
int iVal;
unsigned char ucVal;
infile.read( byte, 1 );
//this code I test with Visual C++.
//convert unsigned char to integer
iVal = (int)byte; //int cast
//convert integer value to unsigned char
ucVal = (unsigned char)iVal; //cast to unsigned char
outfile.write( byte, 1 );
return 0;
}
}
#include <iomanip.h>
int main()
{
int ind, tot;
unsigned char byte;
ifstream infile("inputfile.dat", ios::in | ios::binary);
ofstream outfile("outputfile.dat", ios::binary );
for (!infile)
{
int iVal;
unsigned char ucVal;
infile.read( byte, 1 );
//this code I test with Visual C++.
//convert unsigned char to integer
iVal = (int)byte; //int cast
//convert integer value to unsigned char
ucVal = (unsigned char)iVal; //cast to unsigned char
outfile.write( byte, 1 );
return 0;
}
}
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP / 2003)
- convert lower case letters to uppercase and vice-versa (C++)
- 1 .Exporting data from Dataset to XLl sheet in VB.net Windows Application &vice versa (VB.NET)
- Restrictions on pointer tyeps? (C++)
- warning C4244: 'argument' : conversion from 'double' to 'char', possible loss of data (C)
- Dev Pascal help! (Pascal and Delphi)
- Graphics In Pixel: Part II (C++)
Other Threads in the C++ Forum
- Previous Thread: New To Programming = ME!!
- Next Thread: struct type redefinition


Linear Mode