Click here to Skip to main content
15,891,184 members
Home / Discussions / C#
   

C#

 
AnswerRe: Task.Run.Wait Pin
OriginalGriff3-Jul-20 0:49
mveOriginalGriff3-Jul-20 0:49 
GeneralRe: Task.Run.Wait Pin
Bernhard Hiller3-Jul-20 2:18
Bernhard Hiller3-Jul-20 2:18 
GeneralRe: Task.Run.Wait Pin
OriginalGriff3-Jul-20 4:00
mveOriginalGriff3-Jul-20 4:00 
AnswerRe: Task.Run.Wait Pin
jsc423-Jul-20 6:31
professionaljsc423-Jul-20 6:31 
QuestionStrange characters in JSON RPC server response Pin
pkfox1-Jul-20 3:37
professionalpkfox1-Jul-20 3:37 
AnswerRe: Strange characters in JSON RPC server response Pin
Luc Pattyn1-Jul-20 5:33
sitebuilderLuc Pattyn1-Jul-20 5:33 
GeneralRe: Strange characters in JSON RPC server response Pin
pkfox1-Jul-20 6:23
professionalpkfox1-Jul-20 6:23 
GeneralRe: Strange characters in JSON RPC server response Pin
pkfox1-Jul-20 6:46
professionalpkfox1-Jul-20 6:46 
GeneralRe: Strange characters in JSON RPC server response Pin
Luc Pattyn1-Jul-20 9:36
sitebuilderLuc Pattyn1-Jul-20 9:36 
GeneralRe: Strange characters in JSON RPC server response Pin
pkfox1-Jul-20 10:40
professionalpkfox1-Jul-20 10:40 
GeneralRe: Strange characters in JSON RPC server response Pin
Luc Pattyn5-Jul-20 3:27
sitebuilderLuc Pattyn5-Jul-20 3:27 
GeneralRe: Strange characters in JSON RPC server response Pin
pkfox5-Jul-20 5:45
professionalpkfox5-Jul-20 5:45 
GeneralRe: Strange characters in JSON RPC server response Pin
Luc Pattyn5-Jul-20 6:19
sitebuilderLuc Pattyn5-Jul-20 6:19 
GeneralRe: Strange characters in JSON RPC server response Pin
pkfox5-Jul-20 22:15
professionalpkfox5-Jul-20 22:15 
GeneralRe: Strange characters in JSON RPC server response Pin
Luc Pattyn6-Jul-20 2:12
sitebuilderLuc Pattyn6-Jul-20 2:12 
GeneralRe: Strange characters in JSON RPC server response Pin
pkfox6-Jul-20 3:08
professionalpkfox6-Jul-20 3:08 
GeneralRe: Strange characters in JSON RPC server response Pin
Luc Pattyn6-Jul-20 3:23
sitebuilderLuc Pattyn6-Jul-20 3:23 
GeneralRe: Strange characters in JSON RPC server response Pin
Luc Pattyn6-Jul-20 6:14
sitebuilderLuc Pattyn6-Jul-20 6:14 
GeneralRe: Strange characters in JSON RPC server response Pin
pkfox6-Jul-20 6:56
professionalpkfox6-Jul-20 6:56 
GeneralRe: Strange characters in JSON RPC server response Pin
Luc Pattyn6-Jul-20 7:16
sitebuilderLuc Pattyn6-Jul-20 7:16 
GeneralRe: Strange characters in JSON RPC server response Pin
pkfox6-Jul-20 7:27
professionalpkfox6-Jul-20 7:27 
GeneralRe: Strange characters in JSON RPC server response Pin
Luc Pattyn6-Jul-20 7:43
sitebuilderLuc Pattyn6-Jul-20 7:43 
GeneralRe: Strange characters in JSON RPC server response Pin
pkfox6-Jul-20 8:05
professionalpkfox6-Jul-20 8:05 
QuestionIntegers to Float IEEE 754 Pin
Member 1487212830-Jun-20 16:39
Member 1487212830-Jun-20 16:39 
AnswerRe: Integers to Float IEEE 754 Pin
Luc Pattyn30-Jun-20 17:29
sitebuilderLuc Pattyn30-Jun-20 17:29 
Hi,

one float takes 4 bytes of memory; two shorts would also take 4 bytes. One way to convert one into the other is by mapping them at the same location in memory.

I know of two ways to achieve this:

(1) the techniques available for interacting with unmanaged code and data offer the right tools. Here is how:

using System.Runtime.InteropServices;

		[StructLayout(LayoutKind.Explicit)]
		struct ShortsOverlayFloat {
			[FieldOffset(0)]
			public short I1;
			[FieldOffset(2)]
			public short I2;
			[FieldOffset(0)]
			public float F;
		}

		public float shortsToFloat(short i1, short i2) {
			ShortsOverlayFloat S;
			S.F=0;	// avoids warning
			S.I1=i1;
			S.I2=i2;
			return S.F;
		}


and now
float f = shortsToFloat(9147, 17352);

will yield 400.2791


(2) the more orthodox way is by using some methods of the BitConverter class, such as BitConverter.ToSingle; I haven't checked but I expect they use the above technique behind the scenes. That class uses somewhat different type names, don't let that confuse you!

PS: it is IEEE754, not 745.

Smile | :)
Luc Pattyn [My Articles] Nil Volentibus Arduum


modified 30-Jun-20 23:51pm.

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.