Click here to Skip to main content
15,892,768 members
Home / Discussions / C#
   

C#

 
AnswerRe: Calling a 32-bit .NET dll from a 64-bit .NET application Pin
vikas amin1-Aug-08 8:25
vikas amin1-Aug-08 8:25 
GeneralRe: Calling a 32-bit .NET dll from a 64-bit .NET application Pin
Phil J Pearson3-Aug-08 23:39
Phil J Pearson3-Aug-08 23:39 
GeneralRe: Calling a 32-bit .NET dll from a 64-bit .NET application Pin
vikas amin4-Aug-08 4:29
vikas amin4-Aug-08 4:29 
Questionsetting the selected item in a combobox from the constructor problem Pin
Barry T1-Aug-08 5:02
Barry T1-Aug-08 5:02 
AnswerRe: setting the selected item in a combobox from the constructor problem Pin
Phil J Pearson1-Aug-08 5:19
Phil J Pearson1-Aug-08 5:19 
GeneralRe: setting the selected item in a combobox from the constructor problem Pin
Barry T1-Aug-08 5:34
Barry T1-Aug-08 5:34 
QuestionLooking for an alternative to bit shifting Pin
Jim Warburton1-Aug-08 4:50
Jim Warburton1-Aug-08 4:50 
AnswerRe: Looking for an alternative to bit shifting Pin
Robert.C.Cartaino1-Aug-08 5:50
Robert.C.Cartaino1-Aug-08 5:50 
jimwawar wrote:
Any ideas about a faster approach?


Probably not what you want to do in this case... but you can divide by 256, which gives me about a 5-10% improvement on my system, but I would test that with your setup.

Here's probably what you want to do.

You don't discuss your application but you should be able to write your application logic (the calculations and business algorithms) using the numbers as they are given to you by the hardware... as is. Do all the math, comparisons, and manipulation with respect to how the numbers are represented by the hardware. Then convert them to "normal numbers" only when they need to be presented to the end user.

Here's what I mean (and I am totally making up this example):

Let's say that your hardware is returning temperature data from a large series of sensors. You have to determine if the numbers are in an acceptable range (in my hyptothetical senario, 80,000 +/- 10,000 is acceptable). But the hardware gives you the data in the three-most significant bytes (it's giving you the bytes as 12 34 56 00, which is 203,569,152).

So, instead of writing:
for (int probeID = 0; probeID < 1000000; probeID++)
{
    int data = GetProbeData(probeID);    // Get data from hardware.
    data = data >> 8;                    // Right shift the data to fix the value.
    if (<code>data < 70000</code> || <code>data > 90000</code>)
        Console.WriteLine("Value out of range: {0}", data);
}

Just write:
for (int probeID = 0; probeID < 1000000; probeID++)
{
    int data = GetProbeData(probeID);
    if (<code>data < 17920000</code> || <code>data > 23040000</code>)
        Console.WriteLine("Value out of range: {0}", data >> 8);
}

That assumes that most of the processing time is spent gathering and manipulating the data and not displaying it, which is typically the case.

Oh, and I would probably keep all the number in hex (in the source code) so you can avoid all the conversions:
12 34 56 00 (from hardware) = 203569152 (0x0c223800 in hex)
00 12 34 56 (what you want) = 795192 (0x000c2238 in hex, easier to visualize the bytes)

Enjoy,

Robert C. Cartaino
GeneralMessage Closed Pin
1-Aug-08 7:39
Dan Neely1-Aug-08 7:39 
GeneralRe: Looking for an alternative to bit shifting Pin
Robert.C.Cartaino1-Aug-08 9:12
Robert.C.Cartaino1-Aug-08 9:12 
GeneralRe: Looking for an alternative to bit shifting [modified] Pin
PIEBALDconsult2-Aug-08 10:11
mvePIEBALDconsult2-Aug-08 10:11 
AnswerRe: Looking for an alternative to bit shifting Pin
PIEBALDconsult1-Aug-08 6:34
mvePIEBALDconsult1-Aug-08 6:34 
AnswerRe: Looking for an alternative to bit shifting Pin
Guffa1-Aug-08 11:01
Guffa1-Aug-08 11:01 
GeneralRe: Looking for an alternative to bit shifting Pin
PIEBALDconsult1-Aug-08 15:17
mvePIEBALDconsult1-Aug-08 15:17 
GeneralRe: Looking for an alternative to bit shifting Pin
Guffa2-Aug-08 1:48
Guffa2-Aug-08 1:48 
GeneralRe: Looking for an alternative to bit shifting [modified] Pin
PIEBALDconsult2-Aug-08 5:41
mvePIEBALDconsult2-Aug-08 5:41 
GeneralRe: Looking for an alternative to bit shifting Pin
Guffa2-Aug-08 10:13
Guffa2-Aug-08 10:13 
AnswerRe: Looking for an alternative to bit shifting Pin
PIEBALDconsult2-Aug-08 8:18
mvePIEBALDconsult2-Aug-08 8:18 
AnswerRe: Looking for an alternative to bit shifting [modified] Pin
PIEBALDconsult2-Aug-08 8:52
mvePIEBALDconsult2-Aug-08 8:52 
Questionlocalizable form gridview issue Pin
muharrem1-Aug-08 4:37
muharrem1-Aug-08 4:37 
AnswerRe: localizable form gridview issue Pin
nelsonpaixao1-Aug-08 13:17
nelsonpaixao1-Aug-08 13:17 
GeneralRe: localizable form gridview issue Pin
muharrem2-Aug-08 1:51
muharrem2-Aug-08 1:51 
QuestionService to show form Pin
BenGriffiths1-Aug-08 4:17
BenGriffiths1-Aug-08 4:17 
AnswerRe: Service to show form Pin
paas1-Aug-08 4:43
paas1-Aug-08 4:43 
AnswerRe: Service to show form Pin
vikas amin1-Aug-08 4:53
vikas amin1-Aug-08 4:53 

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.