|
I don't understend what meen N in this code
For binare representation of value i use this function:
<br />
char* BinPrintf(int value)<br />
{<br />
char tmp[256];<br />
memset(tmp, 0, 256);<br />
int tpos = 0;<br />
<br />
while(value)<br />
{<br />
tmp[tpos++] = 0x30+value%2;<br />
value = value >> 1;<br />
}<br />
<br />
char *ret = new char[strlen(tmp)+1];<br />
memset(ret, 0, strlen(tmp)+1);<br />
tpos = strlen(tmp)-1;<br />
value = 0;<br />
while(tpos > -1)<br />
ret[value++] = tmp[tpos--];<br />
<br />
return ret;<br />
}<br />
|
|
|
|
|
Mad__ wrote:
char *ret = new char[strlen(tmp)+1];
memset(ret, 0, strlen(tmp)+1);
tpos = strlen(tmp)-1;
value = 0;
while(tpos > -1)
ret[value++] = tmp[tpos--];
This code could simply be replaced with a call to strrev(tmp) .
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I assume binaryRepresentation is some sort of char array, and that N is actually numberToConvert . That being the case, what you have is working, but you are confusing 0 (ASCII 0) and '0' (ASCII 48). You simply need to change the statement to:
binaryRepresentation[counter] = (char) ((N % 2 ) + 48); Now binaryRepresentation[counter] will contain '0' if N is an even number and '1' if N is an odd number.
Of course, if you wanted to use a "built-in" solution, you could simply use itoa(numberToConvert, binaryRepresentation, 2) .
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanks all for help, I solved it...
-
When in doubt, push a pawn!
-
|
|
|
|
|
<font color=#0000FF>char</font> c;
sscanf("7", "%s %c", &c);
TOXCCT >>> GEII power
|
|
|
|
|
When I made
sscanf( static_cast<char>( N % 2 ) , "%s" , &binaryRepresentation[counter] );
Compiler gives an error like
cannot convert parameter 1 from 'char' to 'const char *
I'm a newbie in C++,
Regards.
-
When in doubt, push a pawn!
-
|
|
|
|
|
kromozom wrote:
sscanf( static_cast( N % 2 ) , "%s" , &binaryRepresentation[counter] );
that's normal, you associate a char with %s
do this :
sscanf( static_cast( N % 2 ) , "%<font color=#FF0000>c</font>" , &binaryRepresentation[counter] );
TOXCCT >>> GEII power
|
|
|
|
|
When I type;
sscanf( static_cast<char>( N % 2 ) , "%c" , &binaryRepresentation[counter] );
Same error occurs, cannot convert char to const char*
Regards,
-
When in doubt, push a pawn!
-
|
|
|
|
|
That is because static_cast( N % 2 ) is not a pointer to a char. I don't know what it is, because N is unknown to me...
Take a look at the prototype of sscanf[^] and then start wondering how you should pass the parameters...
Besides that, the solution that Mad__ gave you looks like what you want...
Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.
|
|
|
|
|
Hi,
can use _itoa(..) function. Have a look @ msdn. it does have a sample too.
Sujan
|
|
|
|
|
Hello all,
In application I am facing handle leak problem.
I am using dev partner tool and oh.exe from MS to trace the leak. But after getting the information from oh.exe I am unable to understand how to get in the code.
for example: using oh.exe i can find that
" 00000ADC gpb.exe File 09e4 \DOCUME~1\E669267\LOCALS~1\Temp\~DFB472.tmp " handle is getting leaked.
Now can you suggest how to locate code with respect to this leak.
Thanks & regards,
Jokhan
|
|
|
|
|
Hi,
I have a toolbar. On click of toolbar button I added a Popup menu. Now when I click on any one of the Popup menu sub item, the toolbar button state should be sunken similar to normal menu.
Can anyone pls help me in this.
Thnaks
Madhavi
|
|
|
|
|
Hi,
Think u must have 2 use something like
CMainFrame *pFrame = (CMainFrame *) GetParentFrame();
TBBUTTONINFO tbi;
tbi.dwMask= TBIF_STYLE;
tbi.cbSize= sizeof(TBBUTTONINFO);
pFrame->m_wndToolBar.GetToolBarCtrl().GetButtonInfo(ID_FILE_SAVE, &tbi);
tbi.fsStyle |= TBSTATE_PRESSED;
pFrame->m_wndToolBar.GetToolBarCtrl().SetButtonInfo(ID_FILE_SAVE, &tbi);
Sometimes this may help u
Sujan
|
|
|
|
|
is there any way i can trace the function where the breakpoint function was reached. I've tried the "crash finder" application but that couldnt trace the function either. I've put exception handlers all over but the application crashes at some point. The application always crashes at the same address and i cant really trace the condition where this is happening. I am writing all my the function names in a file to trace the condition but the application breaks off at a different point with the same address location. Any ideas people?
|
|
|
|
|
have a look at the functions call stack, the processor registers and so useful debuging tools.
otherwise, if you want some help, post a piece of the crashing code...
TOXCCT >>> GEII power
|
|
|
|
|
|
Anonymous wrote:
The application always crashes at the same address and i cant really trace the condition where this is happening.
Have a look at the project's .map file (you might have to add /map to the linker settings). For example, if you know the program is crashing at address 0x17d28a03, you would look in the .map file for the closest address that is less than this value.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Does anyone know of a (preferably free) class library that will accurately represent decimal numbers? we have been using floats but these have problems representing certain numbers and are resulting in rounding errors.
|
|
|
|
|
could you explain a bit more ?
i don't understand why you're talking about a class for integers.
don't you want to use signed /unsigned int /short /long ??
TOXCCT >>> GEII power
|
|
|
|
|
No I mean decimal numbers, like 1.234
float and double are no good at representing certain values (e.g. 0.1)
I need a class that can accruately represent decimal numbers
|
|
|
|
|
Instead of float (4 bytes), use double (8 bytes) or long double (10 bytes) if you need even more precision
|
|
|
|
|
did you have a look at float.h ? you certainly didn't.
you will find many "tools" to manage non real values like infinites, resolution loose, and so...
and about your 0.1, i don't understand why float is not good...
TOXCCT >>> GEII power
|
|
|
|
|
toxcct wrote:
and about your 0.1, i don't understand why float is not good...
float and double are nice containers for floating point numbers, but they aren't accurate, they can't accurately describe 2 1/3 for example.
While double is ok for most apps, it would be a poor choice for eg. insurance companies where the roundings in the complex actuarial formulas would mean filtering away billions of dollars.
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|
|
Technically, decimal means base-10 (deca is Greek for ten). So, rather than using a float type, are you wanting to use an int type?
If you simply need more precision, you might try the DECIMAL type. However, I suspect you are not having precision problems. Most beginners assume you can compare floating-point numbers just like you can non floating-point numbers. For example, this would never produce the desired result:
float a = 0.1;
if (a == 0.1)
... because a is stored internally as 0.0999999999, give or take a few 9s.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|