|
This should work.
void valueFP(bool input[], int n)
{
const int sign = input[0]?-1 : 1;
const int expCoded = (input[1]?4 : 0) + (input[2]?2 : 0) + (input[3]?1 : 0);
const bool denormalized = (expCoded==0) || (expCoded==7);
const int expDecoded = (expCoded^(denormalized?1 : 0)) - 3;
const double significand = (input[4]?0.5 : 0) + (input[5]?0.25 : 0) +
(input[6]?0.125 : 0) + (input[7]?0.0625 : 0) +
(denormalized?0.0 : 1.0);
cout << (significand * sign) << " x 2^" << expDecoded << endl;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Great, thank you. I changed the output to cout << (significand * sign) * (pow(2.0, exp)) << endl; which obviously just gives the floating point value once multiplied out.
After finishing this function I noticed that my one's and two's complement representation function is not working correctly. Any help would be greatly appreciated. Thanks.
void valueONESTWOS(bool input[], int n)
{
bool tempBin[8];
int intVal;
for(int z=0; z<8; z++)
tempBin[z] = input[z];
intVal = valueUINT(tempBin, 8);
if(tempBin[0] == 1)
{
int i = 7;
while(tempBin[i] != 1)
i--;
while(i>=0)
{
if(tempBin[i] == 1)
tempBin[i] = 0;
else if(tempBin[i] == 0)
tempBin[i] = 1;
i--;
}
cout << "One's complement: " << "-" << valueUINT(tempBin, 8) << endl;
cout << "Two's complement: " << "-" << valueUINT(tempBin, 8) + 1 << endl;
}
else
{
cout << "One's Complement: " << intVal << endl;
cout << "Two's Complement: " << intVal << endl;
}
}
|
|
|
|
|
WIth 2's complement, all you need to do is assign the bools to the bits of a signed char - integers on virtually all (if not actually all) processors are represented in 2s complement.
With 1's complement, assign the bools to the bits of a signed char and invert the bits if the most significant bit is set:
void valueONESTWOS(bool input[], int n)
{
const unsigned char raw = (input[0]?128 : 0) + (input[1]?64 : 0) + (input[2]?32 : 0) + (input[3]?16 : 0)
(input[4]?8 : 0) + (input[5]?4 : 0) + (input[6]?2 : 0) + (input[7]?1 : 0);
const signed char twosComplement = raw;
const signed char onesComplement = input[0]?(~raw):(raw);
const bool onesComplementIsNegative = input[0];
cout << "Twos complement = " << twosComplement << endl;
cout << "Twos complement = " << (onesComplementIsNegative?'-':' ') << twosComplement << endl;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I'm trying to change the image from a excel picture object
VARIANT vindex;
vindex.vt = VT_INT;
vindex.intVal = 1;
Excel::Pictures pics;
m_CurrentWS.InvokeHelper(0x00000303,DISPATCH_PROPERTYGET, VT_DISPATCH, &pics, NULL);
Excel::Picture pic = pics.Item(vindex);
now how do I change the image? Is there a way around deleting the image and adding a new one?
modified on Wednesday, March 18, 2009 6:43 AM
|
|
|
|
|
Hi,
Please anyone can tell in which type of window our application
does not get WM_WINDOWPOSCHANING message,
What type of window I need to create so that i'll get this message in my application.
thanx in advance.
|
|
|
|
|
I think Windows will send WM_WINDOWPOSCHANING message for all type of windows. There is no exception in this case.
prvn
|
|
|
|
|
would u please give me sample code to trap this messagfe in dialog based application.
|
|
|
|
|
The same way you would any other message. If you are using VS6, open ClassWizard (Ctrl+W) and click the Class Info tab. In the Message filter combobox, select Window. Now go back to the Message Maps tab. Look in the Messages listbox for WM_WINDOWPOSCHANGING . Using VS200x is similar but I do not have it in front of me.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi,
I use VC++2008, I show The result of my programs in Dos environment.
I want to know how I can showing the executed (RESULT) of my program in C++ (Win32ConsoleApplecation) in the windows environment ?
Thank you
thank you
soso
|
|
|
|
|
Could you explain that a bit more?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Is your program console or GUI (EXE or DLL)?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
my program (Win32 console Application )
thank you
soso
|
|
|
|
|
Then you can use printf() , fprintf(stdout, ...) , or cout to show the result(s) of your program.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
"Windows Environment" means a document or a dialog box. You should start a new project and select "MFC AppWizard" for the type of project, name it whatever, tell it "Yes" "continue" "finish" etc. and then compile & run your project.
The code that's generated is fairly easy to follow (has comments) so do your processing, then use AfxMessageBox() as a sort of printf(). You'll get the hang of it and be able to do more stuff in about a week.
|
|
|
|
|
MFC, STUDIO 2008, ADO
Edited columns into control CListCtrl.
How do to save changed fields into table?
Below fragments the code:
_RecordsetPtr pRecordset;
pRecordset->Open ((IDispatch *) pCommand, vtMissing,
adOpenForwardOnly, adLockOptimistic, adCmdUnknown);
ListView_SetExtendedListViewStyle(m_listCtrl,LVS_EX_GRIDLINES | \
LVS_EX_FULLROWSELECT | LVS_EX_TRACKSELECT);
CListCtrl* m_pListCtrl_3;
m_pListCtrl_3 = (CListCtrl* ) GetDlgItem(IDC_LIST1);
m_pListCtrl_3->SetItemText(0,1,”Test”); // to place into column=1 of
row = 0
of control CListCtrl text string ”Test”
How it to save into table database Access?
Below show 3 variants - all Uncorrecrly:
pRecordset->UpdateBatch(adAffectAll); // not Updated into table!
pRecordset->UpdateBatch(adUpdate); // error C2664: 'Recordset15::UpdateBatch' : cannot convert parameter 1 from 'CursorOptionEnum' to 'AffectEnum'
pRecordset->Update(adUpdate); not Updated into table!
pRecordset->UpdateData(TRUE); // error C2039: 'UpdateData' : is not a member of '_Recordset'
pRecordset->Update(row);
|
|
|
|
|
Hi,
can you pls explain how to get the mData?
mData = ((A2Op & 0xff) << 12) + ((A1Op & 0x0f) << 8) + (Num & 0xff)
A1op = 0x3
A2op = 0x07
Num = 5F
thanks
|
|
|
|
|
See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
okay, i will check 1st.
thank you
|
|
|
|
|
Hi David,
can you pls check if my solution is correct?
thanks a lot...
mData = 7 3 5 F
mData = 0000 0111 0011 0101 1111
Formula:
mData = ((A2Op & 0xff) << 12) + ((A1Op & 0x0f) << 8) + (Num & 0xff);
Given:
A2op = 0x07
A1op = 0x3
num = 5F
Solution:
Alg2op 0000 0000 0000 0000 0111
0000 0000 0000 1111 1111
------------------------
& 0000 0000 0000 0000 0111
------------------------
<<12 0000 0111 0000 0000 0000
Alg1op 0000 0000 0000 0000 0011
0000 0000 0000 0000 1111
------------------------
& 0000 0000 0000 0000 0011
------------------------
<<8 0000 0000 0011 0000 0000
num 0000 0000 0000 0101 1111
& 0000 0000 0000 1111 1111
------------------------
0000 0000 0000 0101 1111
|
|
|
|
|
what type are your numbers? You're only showing 20 bits. INT is 32 bits. CHAR is 8. SHORT is 16. All these values are minimums.
The math is right, though.
|
|
|
|
|
thanks
|
|
|
|
|
Hi All,
i want to add Radio Buttons in a Propertypage which contains many property sheets. i have been told that it is not possible..
if that is the case, can anyone explain me the actual reason behind it?
thanks,
Rakesh S
|
|
|
|
|
Property page containing property sheets!!!
No wonder you don't see any radio buttons.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
i was able to add radio buttons and it is not working..
the application got struck...
may i know the reason sir?
thanks,
Rakesh S
|
|
|
|
|
A property page is like a dialog.
You can place any controls on it.
You're application becoming "struck" would be because of some other reason.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|