Click here to Skip to main content
15,917,320 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: executing code before WM_DISPLAYCHANGE ? Pin
rognorak18-Mar-09 3:38
rognorak18-Mar-09 3:38 
GeneralRe: executing code before WM_DISPLAYCHANGE ? Pin
Nishad S18-Mar-09 4:19
Nishad S18-Mar-09 4:19 
Questionconverting from binary number representation to floating-point representation Pin
steve_o17-Mar-09 9:50
steve_o17-Mar-09 9:50 
AnswerRe: converting from binary number representation to floating-point representation Pin
CPallini17-Mar-09 10:09
mveCPallini17-Mar-09 10:09 
GeneralRe: converting from binary number representation to floating-point representation [modified] Pin
steve_o17-Mar-09 11:41
steve_o17-Mar-09 11:41 
GeneralRe: converting from binary number representation to floating-point representation Pin
CPallini17-Mar-09 11:55
mveCPallini17-Mar-09 11:55 
GeneralRe: converting from binary number representation to floating-point representation Pin
Stuart Dootson17-Mar-09 13:36
professionalStuart Dootson17-Mar-09 13:36 
GeneralRe: converting from binary number representation to floating-point representation [modified] Pin
steve_o17-Mar-09 17:07
steve_o17-Mar-09 17:07 
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;

	// Determines the sign, which is bit 1.
	if(input[0] == 1)
		sign = "-";
	else
		sign = "";

	// Determines the exponent code, which is bit 2-4 (excess-3 representation).
	for(int i=1; i<=3; i++){
		if(input[i] == 1)
			expCode += "1";
		else if(input[i] == 0)
			expCode += "0";
	}
	// Determines the operand, which is bit 5-8.
	for(int j=4; j<=7; j++){
		if(input[j] == 1)
			operand += "1";
		else if(input[j] == 0)
			operand += "0";
	}
	
	// Determines the exponent based on the excess-3 exponent code.
	// Also determines whether normalized or denormalized floating point format will be used.
	if(expCode == "000"){
		exp = -2;
		hiddenBit = 0; // de-normalized!
	}
	else if(expCode == "001"){
		exp = -2;
		hiddenBit = 1; // normalized
	}
	else if(expCode == "010"){
		exp = -1;
		hiddenBit = 1;  // normalized
	}
	else if(expCode == "011"){
		exp = 0;
		hiddenBit = 1; // normalized
	}
	else if(expCode == "100"){
		exp = 1;
		hiddenBit = 1;  // normalized
	}
	else if(expCode == "101"){
		exp = 2;
		hiddenBit = 1; // normalized
	}
	else if(expCode == "110"){
		exp = 3;
		hiddenBit = 1; // normalized
	}
	else if(expCode == "111"){
		exp = 3;
		hiddenBit = 0; // de-normalized!
	}
	else{
		exp = 999;
		hiddenBit = 999;
	}
	cout << sign << hiddenBit << "." << operand << " X " << "2^" << exp << endl;

}


modified on Wednesday, March 18, 2009 12:06 AM

QuestionRe: converting from binary number representation to floating-point representation Pin
CPallini17-Mar-09 22:42
mveCPallini17-Mar-09 22:42 
GeneralRe: converting from binary number representation to floating-point representation Pin
Stuart Dootson17-Mar-09 23:12
professionalStuart Dootson17-Mar-09 23:12 
GeneralRe: converting from binary number representation to floating-point representation Pin
steve_o18-Mar-09 11:08
steve_o18-Mar-09 11:08 
GeneralRe: converting from binary number representation to floating-point representation Pin
Stuart Dootson18-Mar-09 14:11
professionalStuart Dootson18-Mar-09 14:11 
QuestionChange Image in Excel Picture Object Pin
Sister Ray17-Mar-09 7:54
Sister Ray17-Mar-09 7:54 
QuestionWM_WINDOWPOSCHANING?? Pin
sam_psycho17-Mar-09 6:15
sam_psycho17-Mar-09 6:15 
AnswerRe: WM_WINDOWPOSCHANING?? Pin
Akt_4_U17-Mar-09 6:45
Akt_4_U17-Mar-09 6:45 
GeneralRe: WM_WINDOWPOSCHANING?? Pin
sam_psycho17-Mar-09 6:59
sam_psycho17-Mar-09 6:59 
GeneralRe: WM_WINDOWPOSCHANING?? Pin
David Crow17-Mar-09 9:04
David Crow17-Mar-09 9:04 
Questionwindows environment Pin
anassamar17-Mar-09 6:06
anassamar17-Mar-09 6:06 
AnswerRe: windows environment Pin
Code-o-mat17-Mar-09 6:13
Code-o-mat17-Mar-09 6:13 
QuestionRe: windows environment Pin
David Crow17-Mar-09 6:40
David Crow17-Mar-09 6:40 
AnswerRe: windows environment Pin
anassamar18-Mar-09 3:21
anassamar18-Mar-09 3:21 
GeneralRe: windows environment Pin
David Crow18-Mar-09 3:23
David Crow18-Mar-09 3:23 
AnswerRe: windows environment Pin
bulg17-Mar-09 6:58
bulg17-Mar-09 6:58 
QuestionUpdate CListCtrl Pin
durban217-Mar-09 4:17
durban217-Mar-09 4:17 
Questionbitwise Pin
mac_g17-Mar-09 3:57
mac_g17-Mar-09 3:57 

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.