IEEE754

Hi, I need a platform independent function for producing the exact hex for this format and so far this is what I've done:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
ui8* HEX::GetHexFromSF_IEEE754( Text text, ui8 size )
{
	if ( !size ) return NULL
	text.UpperCase();
	wxChar c = text[ 0 ];
	// Iterate
	int  b	=  0, bytes = size;
	int  m  =  0, mBits, mNxt = 2;
	int  i	=  0, iBits, iBytes = 1;
	int  f 	= -1, fBytes = 0;
	int  e	=  0, eBits = 8;
	int  l	=  0, len = text.Length();
	switch ( size )
	{
		// Float
		case 4u:
			mBits = 23;
			break;
		case 6u:
			mBits = 39;
			break;
		// Double
		case 8u:
			mBits = 55;
			break;
		case 10u:
			mBits = 71;
			break;
		// Quadruple
		case 12u:
			mBits = 87;
			break;
		case 14u:
			mBits = 103;
			break;
		// Invalid
		default:
			return NULL;
	}
	// Value
	u8	 buff[ size ];
	bool bin[  size * 2 ];
	u16  mVal[ size ];
	u16  eVal	= 0u;
	// isNeg
	bool dot	= false;
	bool iNeg	= ( c == wxT( '-' ) );
	bool eNeg	= false;
	bool eSgn	= false;
	mVal[ 0 ]	= 0u;
	if ( !iNeg && c == wxT( '+' ) ) l = 1;
	// Capture Integer and Float
	for ( ; ( l < len && m < mBits ); ++l )
	{
		c = text[ l ];
		if ( c >= c0 && c <= c9 )
		{
			c -= c0;
			if ( m == mNxt )
			{
				mNxt += 2;
				++b;
				mVal[ b ] = 0u;
				if ( f < 0 ) ++iBytes;
				else ++fBytes;
			}
			mVal[ b ] << 1u;
			mVal[ b ] += c;
			++m;
		}
		else if ( c == cDot )
		{
			++b;
			f = m + 1;
			fBytes = 1;
		}
		else if ( c == cE ) break;
	}
	if ( l < len )
	{
		// Capture Exponent
		++l;
		c = text[ l ];
		if ( c == wxT( '-' ) ) eNeg = true;
		if ( c == wxT( '+' ) ) ++l;
		for ( ; ( l < len && e < eBits ); ++l )
		{
			if ( c >= c0 && c <= c9 )
			{
				c -= c0;
				eVal << 1u;
				eVal += c;
				++e;
			}
		}
	}
	else eVal = f;
	bin[ 0 ] = iNeg;
	bin[ 1 ] = eNeg;
	for ( i = eBits; i > 1; --i )
	{
		bin[ i ] = ( eVal & 1u );
		eVal >>= 1u;
	}
	int iCnt = eBits + 4;
	ui16 val = mVal[ 0 ], tVal;
	for
	(
		i = eBits + 1;
		( i < iCnt );
		++i
	)
	{
		bin[ i ] = ( val & 0x80 );
		val <<= 1u;
	}
	mVal[ 0 ] = val;
	for // Crush FPN ( Floating point number )
	(
		iCnt = eBits + mBits + 1;
		i < iCnt;
		++i
	)
	{
		tVal = 0u;
		// FPN x 2
		for ( b = mBytes; b >= 0; --b )
		{
			// NOTE: This might be buggy so will need to check this
			val = ( ( mVal[ b ] + tVal ) * 2 );
			tVal = ( ( val & 0xFF00 ) >> 2u );
			mVal[ b ] = ( val & 0xFF );
		}
		// bin[ i ] = ( FPN > 1 )
		bin[ i ] = ( tVal > 0u );
		/*
			if ( bin[ i ] ) FPN -= 1
			We don't need to do this since our integer is stored in tVal which
			is zeroed out before we multiply our FPN. We also don't need to
			worry about infinity carried numbers because our loop will auto
			stop when it has reached the maximum bits.
		//*/
	}
}

This relies on wxWidgets a bit with typedef Text wxString but I'm sure that can be quickly adapted for testing. I'm not in a rush to get an answer because I started my project from scratch in Editra so I haven't actually compiled it yet, my question is what have I done wrong if at all? I've been getting the nagging feeling that I have gotten something wrong here which is why I ask.
I got my information from this URL:
http://en.wikipedia.org/wiki/Single_precision#IEEE_754_single-precision_binary_floating-point_format:_binary32
Last edited on
Oh just in case anyone mentions it: The c0, c9 etc are constants defined just outside the function for use by similar functions as well.
I see two return NULL; but no other return.
Even then, be careful not to return a pointer to an automatic local variable.
thx, i was already aware of that, what I was talking about was how the text was being converted to the float, I keep getting the feeling I've done something wrong there.
Please explain what exactly are you trying to achieve.
Basically I need a platform independent way of converting 1 ( below ) to 2 which then can be seen as 3 in a general purpose Hacking Tool, the previous version I made produced only 32bit and 64bit plus the hex that came out would depend entirely on the platforms implementation - this is obviously not good if you need to take things like emulators into account.
1
2
3
1: 76.87
2: 01000010100110011011110101110001
3: 0x4299bd71
I've made a few modifications which should deal with the basic stuff but the conversion is still leaving a nagging feeling and since I haven't settled on what my new GUI will look like ( to account for small screens ) I cannot compile and test just yet.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
bool HEX::GetHexFromSF_IEEE754( Text text, ui8* buff, ui8 size )
{
	if ( !size ) return false;
	try { buff[ size - 1u ] = 0u; }
	catch ( void* any_error ) { return false; }
	text.UpperCase();
	wxChar c = text[ 0 ];
	// Iterate
	int  b	=  0, bytes = size;
	int  m  =  0, mBits, mNxt = 2;
	int  i	=  0, iBits, iBytes = 1;
	int  f 	= -1, fBytes = 0;
	int  e	=  0, eBits = 8;
	int  l	=  0, len = text.Length();
	switch ( size )
	{
		// Float
		case 4u:
			mBits = 23;
			break;
		case 6u:
			mBits = 39;
			break;
		// Double
		case 8u:
			mBits = 55;
			break;
		case 10u:
			mBits = 71;
			break;
		// Quadruple
		case 12u:
			mBits = 87;
			break;
		case 14u:
			mBits = 103;
			break;
		// Invalid
		default:
			return false;
	}
	// Value
	bool bin[  size * 2 ];
	u16  mVal[ size ];
	u16  eVal	= 0u;
	// isNeg
	bool dot	= false;
	bool iNeg	= ( c == wxT( '-' ) );
	bool eNeg	= false;
	bool eSgn	= false;
	mVal[ 0 ]	= 0u;
	if ( !iNeg && c == wxT( '+' ) ) l = 1;
	// Capture Integer and Float
	for ( ; ( l < len && m < mBits ); ++l )
	{
		c = text[ l ];
		if ( c >= c0 && c <= c9 )
		{
			c -= c0;
			if ( m == mNxt )
			{
				mNxt += 2;
				++b;
				mVal[ b ] = 0u;
				if ( f < 0 ) ++iBytes;
				else ++fBytes;
			}
			mVal[ b ] << 1u;
			mVal[ b ] += c;
			++m;
		}
		else if ( c == cDot )
		{
			++b;
			f = m + 1;
			fBytes = 1;
		}
		else if ( c == cE ) break;
	}
	if ( l < len )
	{
		// Capture Exponent
		++l;
		c = text[ l ];
		if ( c == wxT( '-' ) ) eNeg = true;
		if ( c == wxT( '+' ) ) ++l;
		for ( ; ( l < len && e < eBits ); ++l )
		{
			if ( c >= c0 && c <= c9 )
			{
				c -= c0;
				eVal << 1u;
				eVal += c;
				++e;
			}
		}
	}
	else eVal = f;
	bin[ 0 ] = iNeg;
	bin[ 1 ] = eNeg;
	for ( i = eBits; i > 1; --i )
	{
		bin[ i ] = ( eVal & 1u );
		eVal >>= 1u;
	}
	int iCnt = eBits + 4;
	ui16 val = mVal[ 0 ], tVal;
	for
	(
		i = eBits + 1;
		( i < iCnt );
		++i
	)
	{
		bin[ i ] = ( val & 0x80 );
		val <<= 1u;
	}
	mVal[ 0 ] = val;
	for // Crush FPN ( Floating point number )
	(
		iCnt = eBits + mBits + 1;
		i < iCnt;
		++i
	)
	{
		tVal = 0u;
		// FPN x 2
		for ( b = mBytes; b >= 0; --b )
		{
			// NOTE: This might be buggy so will need to check this
			val = ( ( mVal[ b ] + tVal ) * 2 );
			tVal = ( ( val & 0xFF00 ) >> 2u );
			mVal[ b ] = ( val & 0xFF );
		}
		// bin[ i ] = ( FPN > 1 )
		bin[ i ] = ( tVal > 0u );
		/*
			if ( bin[ i ] ) FPN -= 1
			We don't need to do this since our integer is stored in tVal which
			is zeroed out before we multiply our FPN. We also don't need to
			worry about infinity carried numbers because our loop will auto
			stop when it has reached the maximum bits.
		//*/
	}
	for
	(
		i = 0, b = 0, iNxt = 8, iCnt = size * 2, buff[ 0 ] = 0u;
		i < iCnt; ++i
	)
	{
		if ( i == iNxt )
		{
			iNxt += 8;
			++b;
			buff[ b ] = 0u;
		}
		buff[ b ] <<= 1;
		buff[ b ] += bin[ i ] ? 1u : 0u;
	}
	return true;
}
The first thing I'd do, if I were you, would be to drop the "platform independent" goal.

And if that's out of the question, I'd try to specialize and separate my code for each target platform... all this time being as lazy as I can be... because the more you code, the more you can screw up.

Otherwise, for your purposes and goals, I guess one can't produce much better and nicer looking code than you are, right now.
Well thx anyways, guess I'll find out if I did anything wrong when I get round to compiling it, FPN hex is always the hardest to acquire when converting, I had to do it this way to avoid platform issues in the first place. If you wanna see the previous version look up HackerEX on sourceforge.
For anyone using this function I made a small correction that I noticed, the eNeg variable was not overwritten when the eVal was set to f so I added a variable called mSig to capture the first m that was not 0 then check if it was greater than f and used the return value from that to set eNeg when the exponent is not available.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
bool HEX::GetHexFromSF( Text text, ui8* buff, ui8 size, int mode )
{
	if ( !size ) return false;
	try { buff[ size - 1u ] = 0u; }
	catch ( void* any_error ) { return false; }
	text.UpperCase();
	wxChar c = text[ 0 ];
	// Iterate
	int  b	=  0, bytes = size;
	int  m  =  0, mBits, mNxt = 2, mSig = -1;
	int  i	=  0, iBits, iBytes = 1;
	int  f 	= -1, fBytes = 0;
	int  e	=  0, eBits;
	int  l	=  0, len = text.Length();
	switch ( size )
	{
		// Half
		case 2u:
			mBits = 9;
			eBits = 5;
			break;
		// Float
		case 4u:
			mBits = 23;
			eBits = 8;
			break;
		case 6u:
			mBits = 39;
			eBits = 8;
			break;
		// Double
		case 8u:
			mBits = 51;
			eBits = 11;
			break;
		case 10u:
			mBits = 67;
			eBits = 11;
			break;
		// Quadruple
		case 12u:
			mBits = 80;
			eBits = 14;
			break;
		case 14u:
			mBits = 96;
			eBits = 14;
			break;
		// Invalid
		default:
			return false;
	}
	// Value
	bool bin[  size * 2 ];
	u16  mVal[ size ];
	u16  eVal	= 0u;
	// isNeg
	bool dot	= false;
	bool iNeg	= ( c == wxT( '-' ) );
	bool eNeg	= false;
	bool eSgn	= false;
	mVal[ 0 ]	= 0u;
	if ( !iNeg && c == wxT( '+' ) ) l = 1;
	// Capture Integer and Float
	for ( ; ( l < len && m < mBits ); ++l )
	{
		c = text[ l ];
		if ( c >= c0 && c <= c9 )
		{
			c -= c0;
			if ( mSig < 0 && c > c0 ) mSig = m;
			if ( m == mNxt )
			{
				mNxt += 2;
				++b;
				mVal[ b ] = 0u;
				if ( f < 0 ) ++iBytes;
				else ++fBytes;
			}
			mVal[ b ] << 1u;
			mVal[ b ] += c;
			++m;
		}
		else if ( c == cDot )
		{
			++b;
			f = m + 1;
			fBytes = 1;
		}
		else if ( c == cE ) break;
	}
	if ( l < len )
	{
		// Capture Exponent
		++l;
		c = text[ l ];
		if ( c == wxT( '-' ) ) eNeg = true;
		if ( c == wxT( '+' ) ) ++l;
		for ( ; ( l < len && e < eBits ); ++l )
		{
			if ( c >= c0 && c <= c9 )
			{
				c -= c0;
				eVal << 1u;
				eVal += c;
				++e;
			}
		}
	}
	else
	{
		eNeg = ( mSig > f );
		eVal = f;
	}
	int iCnt;
	if ( mode == HEX_SF_IEEE754_1985 )
	{
		bin[ 0 ] = iNeg;
		bin[ 1 ] = eNeg;
		for ( i = eBits; i > 1; --i )
		{
			bin[ i ] = ( eVal & 1u );
			eVal >>= 1u;
		}
		iCnt = eBits + 4;
		ui16 val = mVal[ 0 ], tVal;
		for
		(
			i = eBits + 1;
			( i < iCnt );
			++i
		)
		{
			bin[ i ] = ( val & 0x80 );
			val <<= 1u;
		}
		mVal[ 0 ] = val;
		for // Crush FPN ( Floating point number )
		(
			iCnt = eBits + mBits + 1;
			i < iCnt;
			++i
		)
		{
			tVal = 0u;
			// FPN x 2
			for ( b = mBytes; b >= 0; --b )
			{
				// NOTE: This might be buggy so will need to check this
				val = ( ( mVal[ b ] + tVal ) * 2 );
				tVal = ( ( val & 0xFF00 ) >> 2u );
				mVal[ b ] = ( val & 0xFF );
			}
			// bin[ i ] = ( FPN >= 1 )
			bin[ i ] = ( tVal > 0u );
			/*
				if ( bin[ i ] ) FPN -= 1
				We don't need to do this since our integer is stored in tVal which
				is zeroed out before we multiply our FPN. We also don't need to
				worry about infinity carried numbers because our loop will auto
				stop when it has reached the maximum bits.
			//*/
		}
		for
		(
			i = 0, b = 0, iNxt = 8, iCnt = size * 2, buff[ 0 ] = 0u;
			i < iCnt; ++i
		)
		{
			if ( i == iNxt )
			{
				iNxt += 8;
				++b;
				buff[ b ] = 0u;
			}
			buff[ b ] <<= 1;
			buff[ b ] += bin[ i ] ? 1u : 0u;
		}
	}
	else return false;
	return true;
}
Just noticed I used the wrong number for moving the bits left in mVal[ b ] ( first loop ), instead of 1u it should have been 4u
I noticed some more errors and corrected them whilst re-writing to simplify the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
bool GetHexFromSF( Text text, void* buffer, int size, int mode )
{
	// Cancel function if size is to small
	if ( size < 2 || size > 18 ) return false;
	// Check if can access last byte
	int  b = size - 1;
	ui8* buff = ( ui8* )buffer;
	try { buff[ b ] = 0u; }
	catch ( void* any_error ) { return false; }
	// Check size is of standard
	int eBits = 0, mBits = 0;
	switch ( mode )
	{
		case HEX_SF_IEEE754:
		{
			if ( !GetHexFromSF_IEEE754_SIZE( eBits, mBits, size ) ) return false;
			break;
		}
		default: return false;
	}
	Char c;
	text.UpperCase();
	ui8 mVal[ size ];
	// Capture FPN ( Floating point number )
	/*
		i: Iteration only
		e: Exponent
		w: Whole Number part of it
		f: Floating part of it
		mVal: Mantissa Root Value
		t: Text position
		tCnt: Letter count
		tVal: Temporary Value ( Mainly to move overflow to next byte position )
	*/
	bool isNaN = false, eNeg = false, mNeg = false;
	int i = 0, e = 0, w = 0, f = 0;
	int mSig = -1, mDot = -1; // mSig is for first significant number
	int t, tCnt = text.length();
	ui16 tVal = 0u;
	ui32 eVal = 0u;
	// Capture Mantissa Sign
	c = text[ 0 ];
	if ( c == cNeg )
	{
		mNeg = true;
		text = text.Right( tCnt - 1 );
		tCnt -= 1;
	}
	else if ( c == cPos )
	{
		text = text.Right( tCnt - 1 );
		tCnt -= 1;
	}
	// Capture Mantissa FPN
	if ( text == wxT( "INFINITY" ) ) b = -1;
	else
	{
		for ( t = 0; t < tCnt; ++t )
		{
			c = text[ t ];
			if ( c >= c0 && c <= c9 )
			{
				c -= c0;
				if ( mSig < 0 && c > 0 ) mSig = i;
				if ( mDot < 0 ) ++w;
				else ++f;
				tVal = mVal[ b ];
				tVal *= 10;
				tVal += c;
				if ( tVal > 0xFF )
				{
					mVal[ b ] = ( tVal & 0xFF );
					tVal >>= 2u;
					--b;
					if ( b < 0 ) break;
				}
				mVal[ b ] = tVal;
				++i;
			}
			else if ( mDot < 0 && c == cDot ) mDot = i;
			else if ( c == cE ) break;
			else isNaN = true;
		}
	}
	// Capture Exponent
	if ( !isNaN )
	{
		if ( b < 0 ) {} // Cancel actions
		else if ( t < tCnt )
		{
			++t;
			eVal = 0u;
			c = text[ t ];
			if ( c == cNeg ) eNeg = true;
			else if ( c != cPos ) isNaN = true;
			else
			{
				for ( ++t; t < tCnt; ++t )
				{
					c = text[ t ];
					if ( c >= c0 && c <= c9 )
					{
						c -= c0;
						eVal *= 10u;
						eVal += c;
					}
					else
					{
						isNaN = true;
						break;
					}
				}
			}
		}
		else if ( mSig > mDot )
		{
			eNeg = true;
			eVal = f;
		}
		else eVal = w;
	}
	if ( isNaN )
	{
		switch ( mode )
		{
			case HEX_SF_IEEE754:
				GetHexFromSF_IEEE754_ISNAN( buff, size );
				break;
		}
		return false;
	}
	else if ( b < 1 )
	{
		switch ( mode )
		{
			case HEX_SF_IEEE754:
				GetHexFromSF_IEEE754_INFINITY( buff, size, mNeg );
				break;
		}
	}
	else
	{
		switch ( mode )
		{
			case HEX_SF_IEEE754:
				GetHexFromSF_IEEE754_BUFF( buff, size, mNeg, mBits,  mVal, eNeg, eBits, eVal );
				break;
		}
	}
	return true;
}
bool GetHexFromSF_IEEE754_SIZE( int& eBits, int& mBits, &int size )
{
	switch ( size )
	{
		// Half
		case  2:
			// 16bit
			eBits = 6;
			mBits = 10;
			break;
		// Float
		case  4:
			// 32bit
			eBits = 8;
			mBits = 24;
			break;
		case  5:
			// 40bit
			eBits = 8;
			mBits = 32;
			break;
		case  6:
			// 48bit
			eBits = 8;
			mBits = 40;
			break;
		// Double
		case  8:
			// 64bit
			eBits = 12;
			mBits = 52;
			break;
		case 10:
			// 80bit
			eBits = 12;
			mBits = 68;
			break;
		// Quadruple
		case 16:
			// 128bit
			eBits = 20;
			mBits = 108;
			break;
		case 18:
			// 144bit
			eBits = 20;
			mBits = 124;
			break;
		default: return false;
	}
	return true;
}
void GetHexFromSF_IEEE754_ISNAN( ui8* buff, int& size )
{
	for ( int b = 0; b < size; ++b )
		buff[ b ] = 0xFF;
}
void GetHexFromSF_IEEE754_INFINITY( ui8* buff, int& size, bool& mNeg )
{
	buff[ 0 ] = mNeg ? 0xFF : 0x7F;
	buff[ 1 ] = 0x80;
	for ( int b = 2; b < size; ++b )
		buff[ b ] = 0u;
}
void GetHexFromSF_IEEE754_BUFF( ui8* buff, int& size, bool& mNeg, int& mBits, ui8* mVal, bool& eNeg, u32& eVal )
{
	int b, m, i, iEnd = size * 8;
	bool bVal[ iEnd ];
	bVal[ 0 ] = mNeg;
	bVal[ 1 ] = eNeg;
	ui16 v, t, num;
	for ( i = eBits + 2; i > 1; --i )
	{
		bVal = ( eVal & 0x1 );
		eVal >>= 1;
	}
	int bEnd = 0;
	for ( b = size - 1; b > 0; --b )
	{
		if ( mVal[ b ] == 0u )
		{
			bEnd = b + 1;
			break;
		}
	}
	v = mVal[ bEnd ];
	if ( v >= 0x10 )
	{
		v -= 0x10;
		num = v & 0xF0;
	}
	else
	{
		v -= 1u;
		num = v & 0xF;
	}
	for ( i = eBits + 3, m = 0; m < mBits; ++i, ++m )
	{
		// FPN -= 1.0
		t = 0u;
		// FPN *= 2
		for ( b = size - 1; b >= bEnd; --b )
		{
			v = ( mVal[ b ] + t ) * 2u;
			t = ( v & 0xFF00 );
			v = ( v & 0xFF   );
			mVal[ b ] = v;
		}
		// If FPN >= 1.0
		bVal = ( t > num );
	}
}
I forgot to add this to bottom of last function
1
2
3
4
5
6
7
8
9
10
11
12
	i = 0;
	iEnd = 8;
	for ( b = 0; b < size; ++b )
	{
		buff[ b ] = 0u;
		for ( ; i < iEnd; ++i )
		{
			buff[ b ] <<= 1u;
			buff[ b ]  += bVal[ i ] ? 1u: 0u;
		}
		iEnd += 8;
	}


Edit: I also forgot a bitwise operation, change the line t = ( v & 0xFF00 ); to t = ( v & 0xFF00 ) >> 8u;
Last edited on
Topic archived. No new replies allowed.