|
i wonder if someone could help me with an issue im having converting a hex value to a binary string..
i am trying to convert the hex string 0x00C000000000 to binary which should work out to be 1100000000000000000000000000000000000000.
i am using std::stringstream to fist convert the hex value to decimal and this is where it seems to be failing.. for the hex string 0x00C000000000 the decimal equivalent should be 824633720832 but i am not getting that..
here is my code
<br />
<br />
std::string hexvalue = "00C000000000";<br />
std::string binary = "";<br />
<br />
long decimalVal;<br />
<br />
std::stringstream sstr(hexvalue);<br />
sstr >> std::hex >> decimalVal;<br />
<br />
std::ostringstream out;<br />
long digit;<br />
bool nonzero = false;<br />
<br />
for (long i = 31; i >=0; i--)<br />
{<br />
digit = (decimalVal >> i) & 1 ;<br />
if (!nonzero && digit)<br />
nonzero = true;<br />
<br />
if (nonzero)<br />
out << digit;<br />
}<br />
<br />
binary = out.str();
by the way, if i set hexvalue to a smaller number then it seems to work. for example.
std::string hexvalue = "12";
can anybody help me out here?
thanks in advance
|
|
|
|
|
doh!!! im a muppet... its always the way isnt it.. no sooner than you ask for help to a problem then you realise what your doing wrong! hehe
as soon as i hit the send button i realised my small "long" was to small, and so ive changed it to __int64 and all is sound!! - ignore me all
std::string hexvalue = "00C000000000";<br />
std::string binary = "";<br />
<br />
__int64 decimalVal;<br />
<br />
std::stringstream sstr(hexvalue);<br />
sstr >> std::hex >> decimalVal;<br />
<br />
std::ostringstream out;<br />
__int64 digit;<br />
bool nonzero = false;<br />
<br />
for (__int64 i = 50; i >=0; i--)<br />
{<br />
digit = (decimalVal >> i) & 1 ;<br />
if (!nonzero && digit)<br />
nonzero = true;<br />
<br />
if (nonzero)<br />
out << digit;<br />
}<br />
<br />
binary = out.str();
-- modified at 11:26 Monday 7th August, 2006
|
|
|
|
|
Hello,
How can change the working directory of NT service from WINNT\system32 to the
exe directory (C++ unmanaged)?
Thanks,
|
|
|
|
|
|
Use GetModuleFileName(NULL, ...) to get the EXE's folder. Use that with SetCurrentDirectory() .
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
If you are bent at using crt routines, then _chdir would do that. Be aware that this routine would internally call the win32 api, SetCurrentDirectory.
|
|
|
|
|
See
SetCurrentDirectory(for set directory)<br />
GetCurrentDirectory(for get current directory)
|
|
|
|
|
We recently switched a rather large project (7 projects in this workspace) from VS2002 to VS2005. This was in anticipation of supporting 64-bit apps, so we had a lot of details to straighten out before we had a working build.
Once the dust had settled, I realized that the browse info for the system no longer works. Whenever I click a symbols name and press F12, for a symbol defined in one of our projects, I get the message "The symbol 'whatever' is not defined." Symbols defined by MFC are handled correctly.
Now, the wierd part: the settings for browse info are all correct, as far as I can tell; I get the correct progress message when thge browse info is created; and the browse info files are where they should be (in the same directory as my .objs). But for some reason, VS2005 can't find them!
Any idea what might be wrong here?
|
|
|
|
|
I am dynamically adding content to a CDialogBar - when the on-screen capacity is reached i want to add a scrollbar to allow the content to be visable.
I understand that CDialogBar will not allow a Scrollbar - so i'm not really sure what to do. I'm quite limted with a CDialogBar as i need it as part of MDI.
Any help appreciated!
-- modified at 11:05 Monday 7th August, 2006
|
|
|
|
|
|
I was trouble by this problem for a long time!
I insert a new dialog template which ID is IDD_DLG_MYDLG
and create a new dialog class named CMydlg;
and I use this dialog in my application :
ex:
void CMyapp::showDlg(CString str)<br />
{<br />
CMydlg *dlg=new CMydlg;<br />
dlg->Create(IDD_DLG_MYDLG, this);<br />
dlg->ShowWindow(1);<br />
dlg->SetWindowText(str);
}
Now, I click one button to show my dialog
ex:
void CMyapp::showMydlg(void)<br />
{<br />
showDlg("my dialog 1");<br />
showDlg("my dialog 2");<br />
}
then, I want to know that the first dialog I created is close or still active,
I don't know how to specify that the dialog , which has some mark to specify it, or else , I use the function showMydlg, it will create lots of dialog, I want to show it if it was not created, or create it if it is not showing!
if some one know ,please tell me , it was so trouble thing, that some one use my application, who continuously clicked one button , so many dialog show make me shy!
if you know what I mean , please give me a better way to solve it !
waiting for answers online!
Just my interest for these common things
|
|
|
|
|
First, the problem with your code is that you have a pointer local to a function (the CMydlg *dlg pointer which is in showDlg). You allocate memory for this pointer but when you reach the end of the function, you don't have any grasp over the pointer anymore. Thus, this will result in a memory leak. Instead of making it local in the function, make it a member of your class (CMyapp). This way, you can control if this dialog is already created (pointer points to a valid dialog class) and you can retrieve the status (if the dialog is visible or not).
And, furthermore, there is no need to make it a pointer, just show/hide it with the CWnd::ShowWindow function.
|
|
|
|
|
I know what you mean, you say that I make it a member of my dlg class.
that creating it when I use it ,and assert it , and show it correctly,
is it?
But the problem is that :
I create a CListCtrl,
and add many item at it !
You know the ICQ:
I simulate it ,
when I dbclicked one item, show a dlg(this dlg is diffrent by its content),
If I dbclicked the same item, show the dlg I just created!
but if the list has so many items, ex 1000,
shall I prepare 1000 pointer at my application as a member at a class?
so I want to find a way that I want to create it when I want to show it !
just I want to decrease the class member pointer!
If it's no way , I think I only use dlg* mydlg[1000] to solve it !
Just my interest for these common things
|
|
|
|
|
xuwenq88 wrote: but if the list has so many items, ex 1000,
shall I prepare 1000 pointer at my application as a member at a class?
So, you have also 1000 different dialog templates ?
Or is it the same dialog but with different data in it ?
In the latter case, you can simply pass the data to the dialog before making it visible.
|
|
|
|
|
I think it so long time, does the clist or ctypedptr can solve it?
Just my interest for these common things
|
|
|
|
|
hi i had written the code to block the specific port using packet filtering API,all work fine but "Pfbindinterfacetoindex" execute successfully but did not block the port so i googled and find another API pfbindinterfacetoindex but it still fails the only problem could be here where give index
GetIpAddrTable( NULL, &dwIface, FALSE);
pIpTable = (PMIB_IPADDRTABLE) malloc(sizeof(PMIB_IPADDRTABLE));
GetIpAddrTable(pIpTable,&dwIface,FALSE);
for (pIpAddr = &pIpTable->table[ dwIface = 0]; dwIface < pIpTable->dwNumEntries; ++dwIface)
++pIpAddr;
PfBindInterfaceToIndex(ihandle,pIpAddr->dwIndex,PF_IPV4,(PBYTE)ip);
tell me what is wrong with this why this is not working i had spend atleast a 1 and half week on that but was failing.
Tasleem Arif
|
|
|
|
|
Maybe instead of
GetIpAddrTable( NULL, &dwIface, FALSE);
pIpTable = (PMIB_IPADDRTABLE) malloc(sizeof(PMIB_IPADDRTABLE));
. . .
you should try this:
dwIface = 0;
GetIpAddrTable( NULL, &dwIface, FALSE);
pIpTable = (PMIB_IPADDRTABLE)malloc(dwIFace);
. . .
I hope it helps.
|
|
|
|
|
it did not work 2.however thanks for reply.
Tasleem Arif
|
|
|
|
|
My project's Classview has become cluttered with a lot of classes and global functions. Many of these are used internally by a component. Is there a way to remove the ones from Classview that I find unnecassary. I am using Microsoft eMbedded Visual C++. Thanks for any help.
-Steve
|
|
|
|
|
You can create folders in ClassView - right-click the project and select New Folder. You can then drag classes into the folder. Unfortunately you can't manage global functions in this way.
An alternative is simply to remove the headers from the project. They aren't required to be part of the project in order to compile - dependency analysis will pick them up. Obviously you should not remove them from source control, if you're using IDE integrated source control.
|
|
|
|
|
Hi all,
I am writing a plugin for windows media player.(UI pluging-Setting)
And I am using its wizard to create it. But when the OnPositionChange is called
oldposition and newPosition give a number like -119927078 or 182007653.
Please help me.
Cheers.
-- modified at 9:49 Monday 7th August, 2006
Every new thing you learn,Gives you a new personality.
|
|
|
|
|
Hello comunity,
i use an COleSafeArray to write data to an excel file, and this works fine, but seems like they(data) are not sorted!
Is there any way to sort an COleSafeArray?
Thanks!
break;
|
|
|
|
|
Sort your items before putting them in the COleSafeArray container, or use Excel's automation features to sort the items after they are stored in the xls file. COleSafeArray doesn't have any built-in sorting functionality.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hello Zac,
thax, that works, sorting before putting in COleSafeArray!
regards
break;
|
|
|
|
|
hi all
how to capture mouse movement over button event. Specifically i need a event when mouse moves over a button and another event when it goes away from that button.
I am doing this in Win32 C based application.
If u have any link to sample code pls specify that.
Thanks
Manjunath S
Bangalore
|
|
|
|