|
Thanks, you are my hero.
I didn´t thought that this is so easy
Pascal
|
|
|
|
|
As he properly realized, going from a number to a 'A' to 'ZZZZ' representation is the same as printing the number base 26 where the digits are the letters 'A' - 'Z'. If you wanted to write a number converter to print that value as decimal, then just change the / 26 to / 10 and the initial character from 'A' to '0'.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
<font color=blue>int</font> iVal = 453; <font color=green>
<font color=blue>char</font> Result[5] = <font color=gray>""</font>;
<font color=blue>if</font> (iVal >= 17577) { <font color=green>
Result[0] = (iVal % 26) - 1 + <font color=gray>'A'</font>;
}
<font color=blue>else</font> {
Result[0] = <font color=gray>'\0'</font>;
}
<font color=blue>if</font> (iVal >= 677) { <font color=green>
Result[1] = (iVal % 26) - 1 + <font color=gray>'A'</font>;
}
<font color=blue>else</font> {
Result[1] = <font color=gray>'\0'</font>;
}
<font color=blue>if</font> (iVal >= 27) { <font color=green>
Result[2] = (iVal % 26) - 1 + <font color=gray>'A'</font>;
}
<font color=blue>else</font> {
Result[2] = <font color=gray>'\0'</font>;
}
<font color=blue>if</font> (iVal >= 1) { <font color=green>
Result[3] = (iVal % 26) - 1 + <font color=gray>'A'</font>;
}
<font color=blue>else</font> {
Result[3] = <font color=gray>'\0'</font>;
}
Result[4] = <font color=gray>'\0'</font>;
<font color=green>
<font color=blue>for</font> (int</font> i = 0, i < 4, i++) {
<font color=blue>if</font> (Result[1] == <font color=gray>'\0'</font>) {
Result[i] = Result[i+1];
}
}
i didnot tested however...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
|
|
|
What value is represented by '0' ?
If you know that, then you have a base 26 system.
See, everything goes up to 26, then it carries over one place.
You are just mapping a base 26 numeric system to letters.
|
|
|
|
|
Sometimes when calling a method "BeginMessage" on an out of process COM component I get the error "The Server Threw an Exception".
I want to use SetUnhandledExceptionFilter in the COM component to set up my own handler "TopLevelHandler" for this error so that I can write a minidump file when it occurs.
My problem is that the handler I set up never gets triggered I just continue to receive the original error "The Server Threw an Exception".
Why wont the COM Component trigger my handler? Is it because there is another global handler that overrides mine? I've noticed that the debugger also never breaks in when the error occurs.
Something clever
|
|
|
|
|
I'm currently reading in a binary file which contains hexadecimal data, however I then need to convert this data from hexadecimal into binary (as well as swap the ordering from least significant bit to most significant bit, i.e. if I get (in hex) C9 6F in I need to swap these to 6F C9 and then convert it into binary, i.e. 0110 1111 1100 1001).
Does anyone know if there is a system call for doing this (or a standard algorithm). I've looks at htons (and other methods) but they rely on the data type being 'short' whereas the data read in from the file is stored as a 'char' in an array.
TIA,
Andy
|
|
|
|
|
Hi Andy,
How do you want to store the binary? So you want a string that reads "0110 1111 1100 1001"? or is it in a 16-bit variable?
As for swapping the bytes, store the bytes in array achOrig, then just bit shift them:
short int w16Bits = (achOrig[0] << 8) | achOrig[1];
Now you will have w16Bits = 6F C9 (in memory)
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Thanks for the bit shift example.
The binary data will eventually get displayed on the screen but we will also be processing the data depending on what type it was originally (i.e. integer, sound, etc...), so if you could give me an example of how to do both types that would be great.
cheers,
Andy
|
|
|
|
|
// given a 16-bit WORD (unsigned short)
WORD wHiLow;
// reverse the two bytes in the word
WORD wLowHi = MAKEWORD( HIBYTE(wHiLow), LOBYTE(wHiLow) );
// obtain binary string
char szBuffer[32];
// binary is radix of 2
itoa(wLowHi, szBuffer, 2);
|
|
|
|
|
Hi All,
This may be a silly question, but how do you seek in a large file. I have to deal with file sizes of 3GB to 5GB and my programme currently uses the C-runtime fopen, fread, fseek, ftell, etc. But with files that large the sizes are beyond the size of 'long' that these functions use. Are there ways around this? (The programme has to run on Win98 - WinXP) I need to be able to get the size of the file, and be able to seek to different parts of it.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Try Windows API,
GetFileSize
Support 64 bits file size
|
|
|
|
|
Thanks, this looks good
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
I don't have any sample code for you.
But to manipulate large files, you should throw C functions away, and
use Windows API to do it, open, seek, get file size, read/write, etc.
It's not difficult to learn those APIs by yourself.
|
|
|
|
|
Koms Bomb wrote:
It's not difficult to learn those APIs by yourself.
Okay, just one question:
C-Runtime provide feof, what is the windows API version of this?
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
RichardS wrote:
C-Runtime provide feof, what is the windows API version of this?
When using ReadFile() , consider this from MSDN:
If the return value is nonzero and the number of bytes read is zero, the file pointer was beyond the current end of the file at the time of the read operation. However, if the file was opened with FILE_FLAG_OVERLAPPED and lpOverlapped is not NULL, the return value is FALSE and GetLastError returns ERROR_HANDLE_EOF when the file pointer goes beyond the current end of file.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi David,
Thanks for the info
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Another way,
GetFileSize to get the file size,
Then use SetFilePointer to 'seek' the file pointer, but you should only seek with zero offset from currect point, then that API will tell you where the currect pointer is.
Now compare that pointer with the file size...
So you don't need to read to the end of the file.
|
|
|
|
|
I've not ever used FAT32, but it supports a maximum file size of 232-1 bytes. That would prohibit your 5GB file from working on Windows 98.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi David,
You are quite right. That's why the C-runtime calls were working well as you could seek 2GB - 2 distance. But now with XP/2000/NT we have the problems.
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
And for whatever it is worth, if you install the C runtime library source code and trace through it far enough, you will find it just ends up mapping all the standard C file flags and functions into calls into the Win32 API anyways.
I had to use that as defense to the argument when someone tried to tell me the C runtime was faster than the Win32 API - how could it be, after a slew of mapping operations, the C runtime functions ended up calling the Win32 API functions anyways...
|
|
|
|
|
Hi Everybody,
In my rich edit application, I just discovered CFM_LINK and am enjoying having clickable links in my CRichEditCtrl. However, when I use streamOut and streamIn to save my control contents to disk and back, all the RTF formatting is preserved except for the links. Please guide me how to save the RTF document along with the hyperlink.
Regards,
Prakash.
A Journey of thousand miles must begin with a single step.
|
|
|
|
|
XP, no SP, the WMP is the one binds with XP.
I put a WMP control on a MFC dialog, then I play it, and adjust the volume.
I want to save the volume when exits, so I tried GetVolume, but it always
returns -600 (the default volume value).
Why? What have I missed? Did any one experience this?
I've post this in MS newsgroup, but got no answers.
Thanks.
|
|
|
|