|
You may want to read up on Big Endian and Little Endian byte order for number representation.
Intel Processors are Little Endian (PCs) Motorola Processors are Big Endian. Depending on how the file was created and on what operating system it could be stored either way.
Little Endian is LSB then MSB. Big Endian is MSB then LSB.
e.g. The hex value 0x7FFF when stored in:
Little Endian = FF 7F
Big Endian = 7F FF
within the file.
Note: Network packets have numbers stored in Big Endian no matter what OS originated them.
I would suggest reading the raw data into a buffer then looking at the buffer contents (2-bytes at a time). You may be able to analyse why the numbers are not showing as you expect.
Note: For a signed short(2-byte integer) the positive values will be 0x0000..0x7FFF and the negative values are 0x8000..0xFFFF.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
It looks, like after you read two bytes into buffer, you put a garbage in high byte, low byte is always correct:
68=0x0044, -188=0xff44
-22=0xffea, 234=0x00ea
130=0x0082, 386=0x0182
... etc
You have a bug somether in your program. Either two varables share the same memory, or you read just one byte and forget another, or....
|
|
|
|
|
hi people i am a college student at the moment currently trying to figure out c and it aint happenin. I need help with 2 things: -
1.i need code for a decimal to hexadecimal converter without using things such as printf etc in the function
2. i need code for a program to convert strings of text all to uppercase again without using printf etc in the function.
any help will be greatly appreciated and will help me not fail me course.
|
|
|
|
|
I have good news and bad news. The good news is - there is google and many, many tutorials out there. The bad news - if this is giving you trouble, it's going to get worse. You need to plug away and do your homework....
C. Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
|
|
|
|
|
Bobsyourmother wrote:
1.i need code for a decimal to hexadecimal converter without using things such as printf etc in the function
Even if you were allowed to use printf() , it would not help in the conversion of base-10 to base-16. While it's true that printf("%#x", 45) would display 0x2d, the number was not actually converted, it was just displayed in a different base.
Counting in different bases is really easy once you know what's going on. The reason that we count in base-10 is because of the number of digits we have on our hands. Were we born with eight digits, our numbering system would be in base-8 instead. That said, the number 2468 in base 10 is:
2x103 + 4x102 + 6x101 + 8x100
In base-8, it would be 4644 or:
4x83 + 6x82 + 4x81 + 4x80
People often think that a computer is this mystical device that somehow manages to do something that people cannot. Wishful thinking but it does the same thing that a person can do only faster and more efficient (e.g., a faster computer doesn't fix bugs, it only makes them faster!). If you cannot do it with pencil and paper, the computer can't do it either! That said, you need to figure out how to do the conversion on paper and then converting that to code will be much easier.
Bobsyourmother wrote:
2. i need code for a program to convert strings of text all to uppercase again without using printf etc in the function.
The ASCII value of 'a' is 97. The ASCII value of 'A' is 65. That should say to you that each lowercase character would need 32 subtracted from it for the uppercase equivalent.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I wish there was a filter to prevent redundant and do my homework for me questions...
These I find are more annoying that advertisements in article forums...
Ahhhh man....
It's frustrating being a genius and living the life of a moron!!!
|
|
|
|
|
I agree but it's a fine line. I've asked a few questions recently which clearly weren't 'real life' scenarios but interview questions I've had and answered. I wanted to know what others think. It's interesting that you get three or for people answering and get three of four different answers. It really is a superb way to learn. I think if you're up front about why you'er asking, then the reader can make the choice whether to answer or not.
Also, to ease my guilt, I do also cut'n'paste the code I've actually tried to get working and not just ask - 'How do I do this?'.
You got to credit this guy with the sheer brassnecked approach. Just hope he has access to CP in his exam (like I wished I had it in my last interview!).
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
In C language:
1. Use sprintf or scanf to store result in string
2. In ASCII table:
small letter: from a=97 dec (0x61) to z=122 dec (0x7a)
big letter: from A=65 dec (0x41) to Z=90 dec (0x5a)
97(a)-32(0x32)=65(A) ... 122(z)-32=90(Z)
|
|
|
|
|
thanx m8 for the help i appreciate all that helped and people who say jus keep tryin dont u think i have this was me last resort come on ive been using c for a month at most and i cant grasp it not me fault and by the way its all assignmemts so no exams thx again helpers i am intedebted
|
|
|
|
|
Greetings,
Frustrations from yesterday.I am trying to load a bitmap into a CBitmap object. I have succesfully done this 100 times before but this time I get an assertion error caused at AfxMakeResourceHandle(). I am calling the LoadBitmap() function at the constructor so it only takes place ones, so its not a problem of loading a bitmap over an existing one.
The image exists and the path is correct and the function is as follows:
[code]
m_bmKnob.LoadBitmap(IDB_51MAX);
[/code]
I have already made sure that there is no duplicate IDB number. Cannot find any informationm about this elsewhere. Something tells me its something very small and silly that I am missing but I have been going over and over it with no luck...
Thanks!
|
|
|
|
|
Some more details...
According to MSDN AfxGetResourceHandle is:
Use the HINSTANCE handle returned by this function to access the
application's resources directly, for example, in calls to the Windows
function FindResource.
Example
//Load the menu specifying the module handle where resource is to be
//found & resource ID
HMENU hMenu = ::LoadMenu(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_PANEL));
I have also tried:
m_bmKnob.FromHandle(LoadBitmap(_AtlBaseModule.GetModuleInstance(),
MAKEINTRESOURCE(IDB_51MAX)));
That compiles and doesn't give an assertion, however later when the bitmap
needs to be used it crashes as actually nothing was ever "sucessfully" loaded
into theCBitmap file.
Does this shed any light into possibilities? I willl post any progress as soon as there is some...have a nice weekend!
|
|
|
|
|
|
Hello,
The project contains several ATL based ActiveX controls with MFC support, the resources are added to the project.
|
|
|
|
|
Well...
it seems the answer is the following:
[code]
CBitmap myBitmap;
AFX_MANAGE_STATE(AfxGetStaticModuleState());
myBitmap.LoadBitmap(IDB_SOMEBITMAP);
[/code]
Now I need to figure out what that all means!
Ciao
|
|
|
|
|
Hi!
I've created an XML file in VS.NET.
I've created a Schema with "Create Shema" on the XML-menu.
My XML-file then look like this:
?xml version="1.0" encoding="utf-8"?<br />
ROOT xmlns="http://tempuri.org/XMLFile1.xsd"<br />
ELEM<br />
/ELEM<br />
/ROOT
(Taken away the > and < signs)
The Schema-file (XMLFile1.xsd) now exists in the current dir.
How do I now validate my XML against that Schema?
When I press: "Validate XML Data" on the on the XML-menu I got the following error:
Visual Studio could not locate a schema for this document. Validation can only ensure this is a well formed XML document and cannot validate the data against a schema.
_____________________________
...and justice for all
APe
|
|
|
|
|
I have a string that's about 450 bytes that I want to assign to a CString, but the string is getting cut off.
CString rawData(i_pszRawData);
int buffLen = rawData.GetLength ();
buffLen is always 230 and not 450 bytes!
If these an embedded zero or null character or binary zero in the string, is there a way around it so that the full 450 is assigned to the CString?
Thanks.
-C
|
|
|
|
|
Wheatbread wrote:
If these an embedded zero or null character or binary zero in the string, is there a way around it so that the full 450 is assigned to the CString?
CStrings are designed to hold zero-terminated strings. if you need to hold arrays with zeros in them, you'll need to use something else, like an array of BYTEs.
Image Toolkits | Image Processing | Cleek
|
|
|
|
|
Hi, I have encountered a problem with a very basic operation. does anybody have any idea about this?
Please see sample code below:
//////////////////////////////////////////
double a, b;
a = 99.99
b = 99.99
if (a <= b){
::MessageBox(NULL, L"TRUE", L"", MB_OK);
}
else{
::MessageBox(NULL, L"FALSE", L"", MB_OK);
}
//////////////////////////////////////////
somehow, it always display FALSE. Anybody knows how to handle this situation?
SDE
|
|
|
|
|
Doubles are NOT precise numbers. They are approximate representations. Whenever you need to compare doubles (or check if zero), you need to do approximate math, using an acceptable number of precision digits to your app. An example is below:
BOOL IsDoubleZero(double dVal)
{
if (dVal < 0.000001 && dVal > -0.000001)
return TRUE;
return FALSE;
}
BOOL AreDoublesEqual(double dVal1, double dVal2)
{
doubld dDiff = dVal1 - dVal2;
if (dDiff < 0.000001 && dDiff > -0.000001)
return TRUE;
return FALSE;
}
onwards and upwards...
|
|
|
|
|
Wow - never knew that. What about floats? Same thing? Hope so else I just screwed up an interview question!
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
Angel1058 wrote:
What about floats? Same thing?
Yes.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I find that absolutely astonishing - you can't compare two doubles or floats for equality? So all these financial and scientific calculations using massive numbers with loads of decimal places aren't accurate - they are approximations?!?
It's not that I am doubting anything written here but I still find that amazing. 99.99 isn't guaranteed to equal 99.99.
Are there any precise types then?
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
Angel1058 wrote:
So all these financial and scientific calculations ... they are approximations?!?
Correct.
Most scientific and financial applications (including my hack TakeStock[^] (forgive the shameless plug - but after all, it is freeware) will instead store floating point numbers as an aggregation of integers (which can be accurately compared).
So a bank balance of $12,345,678.90123 will instead be stored as the integer value 1,234,567,890,123 "milli cents". Since the number of mCents could be extremely large, you need store this value in a collection of int s. In the 70's and early 80's, many programmers used PL/1 which included a DECIMAL data structure for exactly this kind of thing.
Microsoft provides the CURRENCY [^] type that suffices for most financial calculations.
Hope this helps!
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Thanks guys. These have been a great help. I've been thinking about this for quite some time now.
|
|
|
|
|
Is this your actual code? What cmpiler, what settings do you use?
While it is true what was said - floats and doubles are not accurate representations - a simple assignment like yours typically is ok.
(And your ode with default debug/release settings outputs "TRUE" for me).
float and double both use a limited number of digits, certain numbers e.g 1/3, cannot berepresented accurately this way. Also, during calculations, final digits simply get lost. So comparing *results* as replied is a must.
However, you should also consider the alternative:
bool IsEqualRel(double a, double b, double eps = 1e-5)
{
_ASSERTE(a!= 0 && b != 0);
if (a==b) return true;
if (a<0 != b<0) return false;
return fabs((a-b)/a+b)) < eps;
}
bool IsZero(double a, double eps = 1e-5)
{
return a==0 || fabs(a) < eps;
}
which works for all magnitudes except comparison to zero (that's why the separate IsZero function).
With the absolute posted by the other guy, 1e-27 == 100e-27 and 10000000000000 != 10000000000001 which is often not what you need when working with numbers in this range.
I never really know a killer from a savior boost your code || Fold With Us! || sighist | doxygen
|
|
|
|