Hi there,
i have a binary file myfile.bin, the screen output of "od -t x1 myfile.bin"
is
0000000 7f 45 4c .............
0000020 12 13 7f 82
0000024
what i want to get is
7f 45 4c......
12 13 7f 82
but after i use the following commands, the last byte 82 is displayed as
ffffff82 !!??
Here is my commands:
cout << hex << setfill('0');
while (ifs2.get(ch2)) {
cout << int(ch2) << ' ' << setw(2);
}
i'd be grateful if i get any response, thanks a lot
Billy 5 1352
news.hku.hk wrote: Hi there, i have a binary file myfile.bin, the screen output of "od -t x1 myfile.bin" is
0000000 7f 45 4c ............. 0000020 12 13 7f 82 0000024
what i want to get is
7f 45 4c...... 12 13 7f 82
but after i use the following commands, the last byte 82 is displayed as ffffff82 !!??
Because:
((signed char) 0x82) is a negative number ...
Convert it to a signed int and you need a similar negative number:
(int)((signed char) 0x82) == 0xffffff82
Here is my commands:
cout << hex << setfill('0'); while (ifs2.get(ch2)) { cout << int(ch2) << ' ' << setw(2); } i'd be grateful if i get any response, thanks a lot
The way to fix this is to do this...
static_cast<int>(static_cast<unsigned char>(ch2))
The built-in type "char" may be signed or unsigned, that is
implementation dependant.
On Wed, 07 Jan 2004 15:51:27 +0800, news.hku.hk wrote:
Please don't multipost. I answered your question in acllc-c++, now I see
it again here.
In general, try to stick with one group. If you have to sent to multiple
groups, crosspost (with followup if appropriate).
TIA,
M4
"news.hku.hk" <bi******@hkusua.hku.hk> wrote in message news:<3f********@newsgate.hku.hk>... Hi there, i have a binary file myfile.bin, the screen output of "od -t x1 myfile.bin" is
0000000 7f 45 4c ............. 0000020 12 13 7f 82 0000024
what i want to get is
7f 45 4c...... 12 13 7f 82
but after i use the following commands, the last byte 82 is displayed as ffffff82 !!?? Here is my commands:
cout << hex << setfill('0'); while (ifs2.get(ch2)) { cout << int(ch2) << ' ' << setw(2);
cout << setw(2)
<< int(static_cast<unsigned char>(ch2))
<< ' ';
} i'd be grateful if i get any response, thanks a lot Billy
char is (often) a signed integer type. 0x82 is a negative char value
in this case (-126 decimal). Casting to (signed) int retains this
signedness and extends the sign-bit into all available "negativity"
bits in the int (-126 decimal = 0xFFFFFF82). You need to cast the
char to an unsigned-char (range 0..255) before then casting it to an
int to be passed to operator<<
HTH
Tony
sorry about multipost, coz i think different group have different users.
Thanks, all respondants.
"news.hku.hk" <bi******@hkusua.hku.hk> wrote in message
news:3f********@newsgate.hku.hk... Hi there, i have a binary file myfile.bin, the screen output of "od -t x1
myfile.bin" is
0000000 7f 45 4c ............. 0000020 12 13 7f 82 0000024
what i want to get is
7f 45 4c...... 12 13 7f 82
but after i use the following commands, the last byte 82 is displayed as ffffff82 !!?? Here is my commands:
cout << hex << setfill('0'); while (ifs2.get(ch2)) { cout << int(ch2) << ' ' << setw(2); } i'd be grateful if i get any response, thanks a lot Billy
> 7f 45 4c...... 12 13 7f 82
but after i use the following commands, the last byte 82 is displayed as ffffff82 !!?? Here is my commands:
cout << hex << setfill('0'); while (ifs2.get(ch2)) { cout << int(ch2) << ' ' << setw(2); } i'd be grateful if i get any response, thanks a lot Billy
ch2 is converted to signed int in the last output. You have to convert
it to unsigned char instead. This should work:
cout << (unsigned char)(ch2) << ' ' << setw(2); This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: yezanxiong |
last post by:
Hello all,
I am new in asp.net developer,I would like to ask a simple question. how to
display a message box in web application using asp.net?
If I just use
Private Sub btnOK_Click(ByVal...
|
by: MJ |
last post by:
Hi,
I'm hoping this is relatively easy.
I have a report based on a query - when you run the report, a form
opens up and you are prompted for a date range. These are combo boxes
(ie. January...
|
by: MJ |
last post by:
I'm not following... where do I put that?
I put a textbox on my report and put the following property for it:
=!!.Value
This displays 1 (for January 2003).
How do I get it to display...
|
by: Joe Van Meer |
last post by:
Hi,
Is the datalist meant for one table or can I use it to display information
from 2 different tables? Or should I be looking at a datagrid instead?
I began my code and kinda ran into a snag...
|
by: Stephen Noronha |
last post by:
Hi all,
I have a question, I have a restricted page (lots of data) and it really
causes problems if i display all data, so I want to use a pop up to display
the rest of the data, if i use a...
|
by: drew197 |
last post by:
I am a newbie. I am editing someone elses code to make it compatible
with Firefox and Safari.
In IE, when you click on the proper link, a block of text is shown in a
nice paragraph form. But, in...
|
by: cssExp |
last post by:
hello,
Rather than going on a wild explanation on what's the the problem, it'll be much quicker and easier if i let you look at it yourself, so I'll post my page source (actual contents taken out,...
|
by: beebelbrox |
last post by:
Hi, I am new VB programming in Access and I am requesting help with the following code.
WIndows OS MSaccess 2003
This code is attached to an unbound form that will display a specific recordset...
|
by: Academia |
last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it
there.)
I have a listbox populated with Objects.
The Class has a String field that ToString returns.
I assume that...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |