473,383 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Some guidance needed

Hi to all?

For the past couples of weeks I have been programming to make a
program that reads a binary file and produces the equivalent text
file.

The idea is that each byte in the file represents a temperature that
can only go from 0 to 255. So I start by reading the file in to a
character array, and the do an int casting to obtain the value of each
file, so my code is something like this:

ifstream inFile("binary.dat");
ofstream outFile("binary.txt");

inFile.seekg(0, ios::end);
int size = inFile.tellg();
inFile.seekg(0, ios::beg);
char charArray[size];

inFile.read(charArray, size);

for(int= 0; i<size; i++)
{
outFile << (int)charArray[i] <<endl;
}

.... etc ...

I expected the output to range from 0 to 255, but I get values from
-128 to 127!!? and if I use (unsigned int) instead of (int) the output
is even worst.

Is there a better way to see what is the integer equivalent that each
byte holds ?

Regards,
Alexis
_______________________
bo**************@yahoo.com
Jul 19 '05 #1
2 1991
Min
I assumed that 0-255 means, you don't have negative value.
Then try "unsigned char"

"bostonmegarocker" <bo**************@hotmail.com> wrote in message
news:6c**************************@posting.google.c om...
Hi to all?

For the past couples of weeks I have been programming to make a
program that reads a binary file and produces the equivalent text
file.

The idea is that each byte in the file represents a temperature that
can only go from 0 to 255. So I start by reading the file in to a
character array, and the do an int casting to obtain the value of each
file, so my code is something like this:

ifstream inFile("binary.dat");
ofstream outFile("binary.txt");

inFile.seekg(0, ios::end);
int size = inFile.tellg();
inFile.seekg(0, ios::beg);
char charArray[size];

inFile.read(charArray, size);

for(int= 0; i<size; i++)
{
outFile << (int)charArray[i] <<endl;
}

... etc ...

I expected the output to range from 0 to 255, but I get values from
-128 to 127!!? and if I use (unsigned int) instead of (int) the output
is even worst.

Is there a better way to see what is the integer equivalent that each
byte holds ?

Regards,
Alexis
_______________________
bo**************@yahoo.com

Jul 19 '05 #2
Thanks Min,
That worked for me. I really appreciate your help.
- alexis

"Min" <no****@home.com> wrote in message news:<fY**********************@news2.calgary.shaw. ca>...
I assumed that 0-255 means, you don't have negative value.
Then try "unsigned char"

"bostonmegarocker" <bo**************@hotmail.com> wrote in message
news:6c**************************@posting.google.c om...
Hi to all?

For the past couples of weeks I have been programming to make a
program that reads a binary file and produces the equivalent text
file.

The idea is that each byte in the file represents a temperature that
can only go from 0 to 255. So I start by reading the file in to a
character array, and the do an int casting to obtain the value of each
file, so my code is something like this:

ifstream inFile("binary.dat");
ofstream outFile("binary.txt");

inFile.seekg(0, ios::end);
int size = inFile.tellg();
inFile.seekg(0, ios::beg);
char charArray[size];

inFile.read(charArray, size);

for(int= 0; i<size; i++)
{
outFile << (int)charArray[i] <<endl;
}

... etc ...

I expected the output to range from 0 to 255, but I get values from
-128 to 127!!? and if I use (unsigned int) instead of (int) the output
is even worst.

Is there a better way to see what is the integer equivalent that each
byte holds ?

Regards,
Alexis
_______________________
bo**************@yahoo.com

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: chanchito_cojones | last post by:
hi there, I am quite interested in making the move from Access to MySQL. I have grabbed all the software that is needed (MySQL, MySQL Control Center, MaxDB, etc.) and have installed it all...
3
by: David | last post by:
I understand the need for n-tier architecture if an app is to be scaled-up for server farm deployments. And I can also appreciate that separating UI from business-logic from data-access is simply...
2
by: Robert Hanson | last post by:
I am new to the asp.net application building and I have read the information regarding the storing of information using session vs cookies vs viewstate. I am asking for suggestions/guidance as to...
0
by: Patrick.O.Ige | last post by:
This what i got from microsoft! GDluck Dear ASP.NET Customer, This alert is to advise you of the availability of a web page that discusses an investigation Microsoft is currently conducting...
6
by: AMDRIT | last post by:
Hello folks, I appologize for the cross post, but I really need an answer on this: I do not think that I am seeing the whole picture here. I would like to create a windows service and a...
5
by: inetquestion | last post by:
I've got an xml doc which I'm using xslt to create a flat text configuration file. I need to make some dynamic changes in certain circumstances where some of the elements need to have others...
0
by: shinichi | last post by:
Hi all, Im an Oracle newbie here. I have questions here that need guidance from Oracle Expert here. Here it goes: - there are 3 databases that will be used: tableA (2000 records), tableAsub (45000...
0
nirmalsingh
by: nirmalsingh | last post by:
hai everybody, i am new to php. i have no idea to generate web based reports. i even dont know, where to start, how to display it and etc., i am seriously in need of guidance. plz guide me the way...
0
by: darius | last post by:
Hi, having gps navigation web pages I am still curious about voice guidance algorithms/ applications incorporated into navigation systems. I would appreciate your guidance in accessing the...
3
by: Ian Semmel | last post by:
I am not new to computing, but I am to Java and wonder if anyone could point me in the right (or a) direction. Specifically, how are multi-tiered applications put together. There appears to be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.