|
What about two calls to itoa ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
FISH786 wrote: What am I missing?
Well, you need to know what the different operations do and how to use them when building your algorithm. This is a good exercise.
Some hints:
You are e.g. right shifting value by bit steps and put the result in mask . Unless bit equals zero, value and mask will most likely be different. Then you check if mask and value are the same....
It also looks like you're starting from the right (with the least significant bit) in value , but starts from the left in the string....
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Yes that was the idea. To make this work and look up how the operators and shifting works.
Thanks for your help.
|
|
|
|
|
do you mean this
int bit;
for ( bit = 0; bit < 4; bit++)
{
string[3-bit] = '0' + (value & 1);
value >>= 1;
}
string[bit] = '\0';
?
However the above code generates 0010 when value=2 .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: However the above code generates 0010 when value=2
What's wrong with that?
|
|
|
|
|
It is not wrong, of course...
Anyway he may prefer 10 instead of 0010 .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
Hi FISH786,
Change following
int mask = value >> bit;
with
int mask = 8 >> bit;
This code change is applicable for 4 digit binary number only.
regards,
Divyang Mithaiwala
Software Engineer
|
|
|
|
|
Your mask calculations aren't quite right (in that you aren't necessarily generating a mask with a single bit set). Using a loop, I'd implement your conversion to binary like this:
char string[64] = {0};
int value = 2;
for (int bit = 3; bit >= 0; bit--)
{
const int mask = 1 << bit;
string[(3-bit)] = (mask==(value&mask))?'1':'0';
}
string[4] = '\0';
std::cout << string << std::endl;
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
One interpretation looks like...
FISH786 wrote: char string[64];
Change this to:
char string[64] = { '\0' }; FISH786 wrote: int mask = value >> bit;
Remove this.
FISH786 wrote: if ((value & mask) == mask)
Change this to:
if (value & 1) Add this below the if /else :
value = value >> 1; FISH786 wrote: string[4] = '\0';
Remove this.
When the loop ends, your binary string will be in reverse order. A simple call to strrev() will fix that.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi,
I am loading JPG images using follwing code.
image.Load(Image);
HBITMAP hbmp = image.Detach();
if(hbmp == NULL)
{
Error = GetLastError();
}
Load function is failing and I am getting error code 33.
I am searching in google.But I am not getting any useful information.
can anyone help me.
|
|
|
|
|
From WinError.h :
//
// MessageId: ERROR_LOCK_VIOLATION
//
// MessageText:
//
// The process cannot access the file because another process has locked a portion of the file.
//
#define ERROR_LOCK_VIOLATION 33L
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
In order to get the actual message from the OS you may use FormatMessage()
Something like:
DWORD dwError = ::GetLastError();
LPTSTR lpBuffer;
CString csErrorMsg;
if (::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, dwError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT), (LPTSTR)&lpBuffer, 0, NULL) != 0)
{
csErrorMsg.Format("%s", lpBuffer);
}
|
|
|
|
|
hemlat wrote: Load function is failing and I am getting error code 33.
If Load() is failing, you should be calling GetLastError() after it, not Detach() .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi,
I have loaded a bitmap image to a dialog. The exe memory is increased by 1MB. The memory remains the same after closing the dialog. How to clear this memory.
Thanks,
|
|
|
|
|
May be the cleanup jobs are not done fully like bitmap's DeleteObject()
|
|
|
|
|
I have tried with DeleteObject function,but still memory is not getting reduced.
|
|
|
|
|
You should unload the bitmap. Refer the way youd load the bmp.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
I am using LoadBitmap(nIDResource) to load image to dialog
|
|
|
|
|
will the CBitmap object get destroyed (or going out of scope)?
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Please show some code.
Regards,
Sandip.
|
|
|
|
|
Provided that you properly destroy the object, you don't have to worry about what Task Manager or similar tells you since it doesn't tell you what you think it does.
Read more here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
If you are dynamically allocating memory from the C++ heap, the heap will generally not be reduced in size when that memory is freed. One alternative would be to directly allocate your own memory from windows using GlobalAlloc.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi all,
I want to use pimstore.h and aygshell.h in application.
when i include these files in using class than number of errors comes as follows:
pimstore.h(2545) : error C2061: syntax error : identifier 'CEBLOB'
pimstore.h(5465) : error C3121: cannot change GUID for class 'Folder'
1>gt; c:\program files\microsoft sdks\windows\v6.0a\include\shldisp.h(1546) : see declaration of 'Folder'
aygshell.h(286) : error C2061: syntax error : identifier 'SIPSTATE'
1>gt;SMSpadDlg.cpp
please help me for this.
Thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
"_$h@nky_" wrote: when i include these files...
Exactly where did you include them?
"_$h@nky_" wrote: pimstore.h(2545) : error C2061: syntax error : identifier 'CEBLOB'
This seems self-explanatory. No definition for CEBLOB was found prior to line 2545 of pimstore.h .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|