|
Floating point value depends on how do you split the number into mantissa and exponent fields. AFAIK there is no convention on how to do this given a 'boolean array' of arbitrary length.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The program only needs to work for an 8-bit binary input. Floating point format: 1 bit sign, 3 bit exponent (Excess 3 representation), 4 bit significand.
modified on Tuesday, March 17, 2009 6:10 PM
|
|
|
|
|
using you prescription, supposing a IEEE-like format, 10001000 binary turns out to be -0,1875 float (if I didn't make mistakes).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Which bits are which? Is there a leading implied '1' bit on the significand like IEEE754 has?
With your spec, I'd interpret 10001000 as sign = 1 (is that + or -?), exponent = 000 (decodes to -3), significand = 1000. Now...what's the most significant bit of the significand represent? 2^-1? 2^0?
But is that the way the bits are distributed within the byte?
You need a bit more detail in your specification of floating point numbers before you can decode a byte to floating point.
If 10001000 == -0.125, as in your first message, I'd say sign=1 implies negative and that the significand has an implied binary point after the first bit. That would mean your byte decodes as:
1 | negative | 000 | exponent = -3 | 1 | significand = 1.0 |
So, you have - 1.0 x 2^-3, which is -0.125. Does that sound right?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Yeah, I apologize I was not very clear. I am using C++, by the way.
The floating point format should be:
First bit is sign bit(- == 1, + == 0).
Next three bits are the exponent in excess-3 representation.
The last four bits are the significand (with 4 significant bits.)
*I forgot to mention that there is a hidden 1 bit to the left of the binary point for normalized
So, normalized 1 000 1000 would be...
-1.1000 x 2^-3 = -.0011 = -0.1875
and, using denormalized 1 000 1000 would be...
-0.1000 x 2^-2 = -.0010 = -0.125
Which explains the two different answers, however I want to use denormalized here.
In my program, it takes the users input for the binary byte and puts the input into a bool array of size 8. I want to write a function, "valueFP(bool input[], int 8)". Here is what I have, just kind of a test function. I need to make it so that the string output becomes it's mathematical representation.
void valueFP(bool input[], int n)
{
string sign;
string expCode = "";
int hiddenBit;
int exp;
string operand = "";
string tempVal;
float fpDecVal;
if(input[0] == 1)
sign = "-";
else
sign = "";
for(int i=1; i<=3; i++){
if(input[i] == 1)
expCode += "1";
else if(input[i] == 0)
expCode += "0";
}
for(int j=4; j<=7; j++){
if(input[j] == 1)
operand += "1";
else if(input[j] == 0)
operand += "0";
}
if(expCode == "000"){
exp = -2;
hiddenBit = 0;
}
else if(expCode == "001"){
exp = -2;
hiddenBit = 1;
}
else if(expCode == "010"){
exp = -1;
hiddenBit = 1;
}
else if(expCode == "011"){
exp = 0;
hiddenBit = 1;
}
else if(expCode == "100"){
exp = 1;
hiddenBit = 1;
}
else if(expCode == "101"){
exp = 2;
hiddenBit = 1;
}
else if(expCode == "110"){
exp = 3;
hiddenBit = 1;
}
else if(expCode == "111"){
exp = 3;
hiddenBit = 0;
}
else{
exp = 999;
hiddenBit = 999;
}
cout << sign << hiddenBit << "." << operand << " X " << "2^" << exp << endl;
}
modified on Wednesday, March 18, 2009 12:06 AM
|
|
|
|
|
Why are you using, at the same time the 'normalized' form and the 'de-normalized' one (depending on exponent)?
Do you know that, with the above code 10001000b != -.125f ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
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
|
|
|
|