|
Yea, but i am supposed to be 100% finished tommorrow
"The beauty of Grace is that it makes life not fair" Relient K, Be my Escape
|
|
|
|
|
how can i add two integers(numbers) without using + operator,rather by doing bit manupolation???
|
|
|
|
|
May I ask why you want to do that?
|
|
|
|
|
its my university assignment, in which we have to add 2 numbers but without + operator, can u help me in this?
|
|
|
|
|
In that case you should really do it yourself! You don't want to be caught cheating, do you?
|
|
|
|
|
yeah! but we really haven'nt been taught abt it...i m working abt it, if u dont wana help out then its ok.
thnx
|
|
|
|
|
Well it is not difficult to adapt the standard operation you do on paper with base-10 numbers to a base-2 system.
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
|
|
|
|
|
You can do this like, have two integers and a result integer.
For each input integer, check its bits from right to left(least significant bit to most)
If the bit value is one and same bit of resulting integer is zero, make resulting integer's bit to one.
If both are one then keep this bit's position, check which bit on left side of resulting integer value is zero, make it one and make other bits on right side until above kept position to zero.
Need to do for each integer input.
The process could be something like this or more easier, think yourself..
Thanks,
Suman
--
"Programming is an art that fights back!"
|
|
|
|
|
|
the algorithm for this is very short: basically, four operations in a loop.
some key points to think about:
if the binary representation of the two numbers you are adding do not have any 1 bits in common, addition is equivalent to a simple OR. 0x01 | 0x02 = 0x03, 0x08 | 0x03 = 0x0b (8 + 3 = 11 = 1000b + 0011b = 1011b). but, such a situation is the exception.
so, what do you do when numbers share bits?
(1 + 1 = 2)
0001b
0001b +
----------
0010b
(3 + 3 = 6)
0011b
0011b +
----------
0110b
(9 + 3 = 12)
1001b
0011b +
----------
1100b
see the pattern ?
1 + 1 = 2 but there is no 2 in base2, so put a zero, carry the one to the next column and do it again.
|
|
|
|
|
Using Visual C++ 6.0 MFC in SDI application
Under certain conditions I want my OnDraw routine to display a blank window, instead of what was previously drawn there. When I use the InvalidateRect(0) function, the OnDraw gets called, but I am looking for some window function that will clear everything. How do I do that?
Thanks
|
|
|
|
|
Why don't you put a flag in your OnDraw ()?
OnDraw ()
{
if (bBlank)
return;
Your Drawing code...
}
and bBlank = TRUE or FALSE as you need the blank window or not
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
The problem was that I would set a flag for my OnDraw routine to do as you suggested, but in the function that set that flag I simply did
flag = NOTDRAW;
Invalidate(0);
When I did this, with the OnDraw routine simply returning when it saw that flag, the old info in the client window would not be erased.
When I changed things to
Invalidate(0);
flag = NOTDRAW;
Invalidate(0);
in the function that set the flag, then the old info in the client window would get erased. So I'm confused as to what is happening with the Invalidate(0) function.
|
|
|
|
|
I am not sure why it happens. I usually use the Invalidate () without 0 and just afterwards an UpdateWindow (). It is supposed that Invalidate triggers the update, but I got used to that when I start coding in MFC because of some tutorials I used. The only problem with this is that depending on how much info is on the screen it can make it flick a bit.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Kwanalouie wrote: I am looking for some window function that will clear everything
Write a handler for WM_ERASEBKGND [^]
/ravi
|
|
|
|
|
I have a doubt whether it is possible to creat a C++ object in C with new operator. As show below?
//////////////////////////ExmCPP.cpp///////////////////////////////////////
class TDM_API
{
public:
TDM_API();
~TDM_API();
int WriteIntoLog(const string sStr);
}
////////////////////ExampleC.c File/////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
DLLEXPORT int td_init()
{
TDM_API* td = new TDM_API();
m_nHandle = (int) td;
td->WriteIntoLog("This is for test");
return (int) m_nHandle;
}
|
|
|
|
|
By default, Visual Studio will compile ExampleC.c as a C program, and will signal an error on the new operator. You can set a compile option to compile it as C++, which eliminates the error.
|
|
|
|
|
can you please guide me to change the compailer option in VS 6.0.
Thanks,
Nandu
|
|
|
|
|
Hmmm. I just started up VC6. It doesn't have an option for compiling a .C source file as C++. This option must have come later, in Visual Studio .NET or 2003.
You may have to rename your .C file to .CPP in order to get VC6 to compile it as C++.
|
|
|
|
|
Thanks, the above solution solved my problem.
|
|
|
|
|
Hi all,
Esc Button use for Close the Dialog Box.i want to remove the funcnality how can i do this.
Thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
If you are using MFC, add an OnCancel() handler to your CDialog -derived class.
|
|
|
|
|
He wants to remove the OnCancel, not to call it :P
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
It sounded like he wanted to prevent the ESC key from closing the dialog. To do that in an MFC application with a CDialog -derived dialog class, you add an empty OnCancel member function.
You can't "remove" OnCancel in any case. The CDialog window procedure is going to call it, either in your class or the base class.
|
|
|
|
|
Gary R. Wheeler wrote: It sounded like he wanted to prevent the ESC key from closing the dialog
Yes, but if you add the OnCancel () in MFC it usually comes with the return CDialog::OnCancel ()... you just said to add the OnCancel but nothing about an empty OnCancel (what you do have said now )
EDIT:
Gary R. Wheeler wrote: add an OnCancel() handler
Sorry I missread the word handler , so actually the dialog has the function in header but no code in definition, isn't it?
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|