Click here to Skip to main content
15,897,519 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralSerial comm in VC++ Pin
MaheshKalose24-Mar-05 6:15
MaheshKalose24-Mar-05 6:15 
Generalgrayout a text Pin
mk_le24-Mar-05 5:32
mk_le24-Mar-05 5:32 
GeneralRe: grayout a text Pin
Michael Dunn24-Mar-05 13:33
sitebuilderMichael Dunn24-Mar-05 13:33 
GeneralConvert To Binary Pin
Static(x)24-Mar-05 4:38
Static(x)24-Mar-05 4:38 
GeneralRe: Convert To Binary Pin
David Crow24-Mar-05 5:25
David Crow24-Mar-05 5:25 
GeneralRe: Convert To Binary Pin
ddmcr24-Mar-05 5:54
ddmcr24-Mar-05 5:54 
GeneralRe: Convert To Binary Pin
David Crow24-Mar-05 5:59
David Crow24-Mar-05 5:59 
GeneralRe: Convert To Binary [edited] Pin
toxcct24-Mar-05 5:36
toxcct24-Mar-05 5:36 
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>// For example</font>
CString strVal = <font color=#808080>""</font>;  <font color=#008000>// CString because more easy to use</font>

<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]
GeneralRe: Convert To Binary Pin
ddmcr24-Mar-05 6:34
ddmcr24-Mar-05 6:34 
GeneralRe: Convert To Binary Pin
toxcct24-Mar-05 6:39
toxcct24-Mar-05 6:39 
GeneralToolbar problems... Pin
Tommy2d24-Mar-05 4:25
Tommy2d24-Mar-05 4:25 
GeneralPlease help me! Pin
dSolariuM24-Mar-05 4:25
dSolariuM24-Mar-05 4:25 
GeneralRe: Please help me! Pin
toxcct24-Mar-05 5:18
toxcct24-Mar-05 5:18 
Generalcurrently connected user Pin
shaans24-Mar-05 2:55
shaans24-Mar-05 2:55 
GeneralRe: currently connected user Pin
David Crow24-Mar-05 4:06
David Crow24-Mar-05 4:06 
GeneralRe: currently connected user Pin
shaans24-Mar-05 17:26
shaans24-Mar-05 17:26 
GeneralRe: currently connected user Pin
David Crow25-Mar-05 2:07
David Crow25-Mar-05 2:07 
GeneralSend mail with attachment Pocket PC 2003 Pin
verma-rahul24-Mar-05 1:34
verma-rahul24-Mar-05 1:34 
Generalfun(char*) and fun(char) Pin
bobi_zcl24-Mar-05 0:37
bobi_zcl24-Mar-05 0:37 
GeneralRe: fun(char*) and fun(char) Pin
Abyss24-Mar-05 1:23
Abyss24-Mar-05 1:23 
GeneralRe: fun(char*) and fun(char) Pin
toxcct24-Mar-05 1:27
toxcct24-Mar-05 1:27 
GeneralRe: fun(char*) and fun(char) Pin
bobi_zcl24-Mar-05 1:43
bobi_zcl24-Mar-05 1:43 
GeneralRe: fun(char*) and fun(char) Pin
David Crow24-Mar-05 4:23
David Crow24-Mar-05 4:23 
GeneralRe: fun(char*) and fun(char) Pin
toxcct24-Mar-05 5:39
toxcct24-Mar-05 5:39 
GeneralCWebBrowser - Web Data Pin
sweep12324-Mar-05 0:37
sweep12324-Mar-05 0:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.