|
Giorgi Moniava wrote:
can you give me any link where i can find information about converting from decimal to binary
I found this in my toolbox. It's old so adjust as necessary:
void DWORD_To_BinaryString( DWORD value,char string[] )
{
for (int bit = 0; bit < 32; bit++)
{
DWORD mask = 0x80000000 >> bit;
if ((value & mask) == mask)
string[bit] = '1';
else
string[bit] = '0';
}
string[32] = '\0';
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanks David for your attention, but i need function like
CString string_To_BinaryString( CString value )
{
CString result;
...
...
return result;
}
you know actually variable 'value' in my program appears to be huge number example : "72389472389472389....234234234234"
it maybe 300 digit or more.thats why standard algorithm(division by 2,...) is very slow.you know i am a little inexperienced programmer so things like '0x80000000' are not similiar to me , i would be very thankful to you if you could give me a little explanation about how to adjust your function in order to get what i need.
Thanks in advance
m0n0
|
|
|
|
|
I did a program like this before about 14 years ago. There was no limit to the length of the operands and the supported operators were +, -, *, /, ^, and !. I did not have to convert anything to binary, though.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
well, i don't know any way to convert a string with an integer long enough into another "binary" string.
if you work directly on an integer, you can do this :
<font color=#0000FF>int</font> iVal = 125932; <font color=#008000>
CString strVal = <font color=#808080>""</font>; <font color=#008000>
<font color=#0000FF>while</font> (<font color=#008000></font>) {
strVal.Insert(0, ((iVal & 0x00000001) ? <font color=#808080>"1"</font> : <font color=#808080>"0"</font>));
iVal >>= 1;
} BUT ! if you have a string, unless you cast its content into a binary (short, int or long) type, this method is not applyable beacause of the risk of bits lack (overflow).
do you already have some shorst ideas on the subject to share ?
[EDIT]
...And as Mr Giorgi Moniava asked to Mr Prakash, i'll try to explain a bit more my code (which is quite similar to Mr Prakash's).
- with CString::Insert(0, ...), I add at position 0 the second parameter (i hope i place them in the right order).
- with (iVal & 0x00000001), I use the Bitwise-AND operation to get if the lower bit is set at 1 or 0. In fact, I should have written ((iVal & 0x00000001) == 0x00000001). this operation does this :
iVal -> 100010101101011010010100001010011
& 000000000000000000000000000000001
-------------------------------------
== 000000000000000000000000000000001
iVal -> 100010101101011010010100001010100
& 000000000000000000000000000000001
-------------------------------------
== 000000000000000000000000000000000
that's what Mr Prakash does with its mask .
- if you know about the C/C++ operator ?: , you also know that if its 1st parameter (the condition) is true, then the 2nd parameter is returned, otherwise, it is the 3rd parameter to be returned.
This way, the condition is true if the LSB (Lower Significant Bit) is set to 1. So, i insert "1" in the string.
- Then, i shift all the bits to the right and test again what i've just done before...
[/EDIT]
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
i copied this code to my program and it works ideally to my surprise ,because i am unfamiliar to things like "0x00000001" , but unfortunately i need to cenvert Strings to Binary Strings ex : "17"DEC="10001"BIN and they appear to be very long(100 or more digits), anyway i'd be very thankful to you if you could give me a little explanation on how your code works,
THanks in advance
m0n0
|
|
|
|
|
Giorgi Moniava wrote:
anyway i'd be very thankful to you if you could give me a little explanation on how your code works,
certainly....
read again my previous post. i've added some explainations about my code at its end...
cheers,
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hi!
I'm designing a toolbar for my aplication with 64x64 buttons. I want to store them all as 256color bitmaps in resources for my app.. This is the code i'm using:
<br />
m_wndToolBar = ::CreateWindowEx (0, TOOLBARCLASSNAME, NULL,ATL_SIMPLE_TOOLBAR_PANE_STYLE, 0, 0, 64, 64, m_hWnd,(HMENU) LongToHandle (ATL_IDW_TOOLBAR), _Module .GetModuleInstance (),NULL);<br />
<br />
TBBUTTON tbb[3];<br />
char blah[250];<br />
sprintf(blah,"Hamsters!!!");<br />
<br />
tbb[0].idCommand = 1; <br />
tbb[0].fsState = TBSTATE_ENABLED; <br />
tbb[0].fsStyle = BTNS_BUTTON|BTNS_AUTOSIZE;<br />
tbb[0].dwData = 0; <br />
tbb[0].iBitmap = 0;<br />
tbb[0].iString = (int)&blah;<br />
<br />
tbb[1].idCommand = 2; <br />
tbb[1].fsState = TBSTATE_ENABLED; <br />
tbb[1].fsStyle = BTNS_BUTTON|BTNS_AUTOSIZE;<br />
tbb[1].dwData = 0; <br />
tbb[1].iBitmap = 1;<br />
tbb[1].iString = (int)&blah; <br />
<br />
tbb[2].idCommand = 3; <br />
tbb[2].fsState = TBSTATE_ENABLED; <br />
tbb[2].fsStyle = BTNS_BUTTON|BTNS_AUTOSIZE; <br />
tbb[2].dwData = 0;<br />
tbb[2].iBitmap = 1;<br />
tbb[2].iString = (int)&blah;<br />
<br />
<br />
list .Create(64, 64, ILC_COLOR, 1, 1);<br />
CBitmap bmSmall;<br />
bmSmall .LoadBitmap (IDB_BITMAP1);<br />
list .Add (bmSmall);<br />
list .SetBkColor (::GetSysColor (COLOR_3DFACE));<br />
<br />
<br />
m_wndToolBar .SetButtonStructSize (sizeof (TBBUTTON));<br />
m_wndToolBar .SetExtendedStyle (TBSTYLE_EX_DRAWDDARROWS|TBSTYLE_EX_MIXEDBUTTONS);<br />
m_wndToolBar .SetMaxTextRows (1);<br />
m_wndToolBar .SetImageList(list);<br />
m_wndToolBar .SetButtonSize (64,64);<br />
m_wndToolBar.AddButtons(3,tbb);<br />
<br />
m_wndToolBar.UpdateWindow();<br />
My problem is that the toolbar doesn't want to show any of my buttons' images! What am i doing wrong? Thanks
|
|
|
|
|
Hi,
I want to create a CAsyncSocket in an array and then get this
variable.I used this but dinn't work:
CObArray ob;
CAsyncSocket cl1;
CAsyncSocket cl2;
CAsyncSocket server;
ob.Add(&cl1);
ob.Add(&cl2);
server.Accept((CAsyncSocket*)ob[0]);
Please help me and tell me what is wrong?
Thanks.
|
|
|
|
|
in you code, ob is a CObArray. What does the CObArray::operator[]() return ??
maybe the compiler cannot cast from the returned value to CAsynSocket*
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hai, can u help me in my problem? how can i find out how many users are currently connected to one application.whether i can store in memmory?then how?pls help me...
shan
|
|
|
|
|
Is this an application that you wrote that you are wanting to keep a connection-count of, or are you wanting to know how many connections there are to some other application?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
hai , i want to know connection count of each application(client server based application)
shan
|
|
|
|
|
I'm guessing that you already have code on the server side that handles client requests. Yes?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I want to attach a file with the mail to send in Pocket PC 2003.IMessage provides the method to create attachment and write stream in it .how can i attach an existing file stored.
pls help me.
Learner always
|
|
|
|
|
Hi:
I overload funcion fun(char) and fun(char*),when I call fun(0),the compiler said:" ambiguous called ....",but when I call fun(1),the compiler will select fun(char).why?
I also define fun(int) and fun(int*),to my surprise,I call fun(0) in the same way. The compiler compile successfully and select fun(int),Why?
your friend:bobi
|
|
|
|
|
I'm not a compiler expert, but suppose that the compiler tries to convert (cast) the input argument to something. Since 0 is by default an integer it tries to cast to char but it also can be casted to NULL pointer. So the compiler doesn't know which is the best solution. In the second case the 0 is an integer and the compiler found the method, doesn't need conversion (casting). I suppose if you call the function as fun(0L) it will have the same result as in the previous case...
To resolve the problem call the function as fun((char)0) .
Hope this help,
Abyss
|
|
|
|
|
i also though of an implicit cast (that is what the compiler does actually), but there should not be any difference between 0 and 1 in calling the function. if 0 is casted to char, so 1 should be too. if 0 is casted to char* (NULL pointer), then 1 should be casted to address 1...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
oH,dear:
I try calling fun(0L),the compiler compile successfully and select fun(int) still.
your friend:bobi
|
|
|
|
|
bobi_zcl wrote:
I overload funcion fun(char) and fun(char*),when I call fun(0),the compiler said:" ambiguous called ....",but when I call fun(1),the compiler will select fun(char).why?
Was this not answered sufficiently here and here?
0 is an integral constant expression. For the char /char* case, neither is a better match for the 0 than the other, hence the ambiguity error. For the int /int* case, fun(int) is an exact match for 0, thus no error.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
|
I have added the CWebBrowser control to my MFC program. I can Get/Set the URL, using methods Navigate and get_LocationURL but was wondering if it is possible to get hold of some of the data being displayed on the Web Page; e.g. labels, tables elements and current Combo selection.
Cheers,
|
|
|
|
|
|
how can we find out the difference(number of days) between system date and decide date.
|
|
|
|
|
|
You can check COleDateTime class as well.
"Aerodynamically, the bumble bee shouldn't be able to fly, but the
bumble bee doesn't know it so it goes on flying anyway." - Mary Kay Ash
My Articles
|
|
|
|