Click here to Skip to main content
16,014,650 members
Home / Discussions / C#
   

C#

 
GeneralRe: New Interface Pin
J. Dunlap3-Feb-07 17:09
J. Dunlap3-Feb-07 17:09 
AnswerRe: New Interface Pin
Judah Gabriel Himango3-Feb-07 16:53
sponsorJudah Gabriel Himango3-Feb-07 16:53 
GeneralRe: New Interface Pin
max292973-Feb-07 17:03
max292973-Feb-07 17:03 
QuestionC# - Binary Operations? Pin
wbjohnson3-Feb-07 14:14
wbjohnson3-Feb-07 14:14 
AnswerRe: C# - Binary Operations? Pin
H.M.J.3-Feb-07 14:58
H.M.J.3-Feb-07 14:58 
QuestionExtracting bytes from a 32-bit value Pin
H.M.J.3-Feb-07 13:12
H.M.J.3-Feb-07 13:12 
AnswerRe: Extracting bytes from a 32-bit value Pin
Christian Graus3-Feb-07 14:04
protectorChristian Graus3-Feb-07 14:04 
AnswerRe: Extracting bytes from a 32-bit value [modified] Pin
Luc Pattyn4-Feb-07 1:29
sitebuilderLuc Pattyn4-Feb-07 1:29 
There is an alternative, that may be interesting when many variables need to
available in both packed and unpacked form.

Using structs you can obtain a "union" effect in C# in the following way:

using System.Runtime.InteropServices;	// StructLayout

[StructLayout(LayoutKind.Explicit)]
public struct Overlay {
	[FieldOffset(0)]public uint u32;
	[FieldOffset(0)]public byte u8_0;
	[FieldOffset(1)]public byte u8_1;
	[FieldOffset(2)]public byte u8_2;
	[FieldOffset(3)]public byte u8_3;
}
public override void Run() {
	Overlay overlay=new Overlay();
	overlay.u32=0x12345678;
	log("lo to hi: "+overlay.u8_0.ToString("X2")+" "+overlay.u8_1.ToString("X2")+
		" "+overlay.u8_2.ToString("X2")+" "+overlay.u8_3.ToString("X2"));
}

On a little-endian machine (such as Intel x86) the Run method will log
"lo to hi: 78 56 34 12"

Be careful though, you are responsible for the offset values !

Smile | :)




-- modified at 11:54 Sunday 4th February, 2007

Luc Pattyn

QuestionDocking Pin
dsl/fahk3-Feb-07 12:51
dsl/fahk3-Feb-07 12:51 
Questionhow to set focus on datagridview row ? Pin
hdv2123-Feb-07 7:39
hdv2123-Feb-07 7:39 
AnswerRe: how to set focus on datagridview row ? Pin
Aleksandar Smudja16-Feb-07 12:05
Aleksandar Smudja16-Feb-07 12:05 
QuestionChat Program Pin
max292973-Feb-07 7:23
max292973-Feb-07 7:23 
AnswerRe: Chat Program Pin
Michael P Butler3-Feb-07 8:45
Michael P Butler3-Feb-07 8:45 
GeneralRe: Chat Program Pin
max292973-Feb-07 15:05
max292973-Feb-07 15:05 
Questionwrappers Pin
a4a93-Feb-07 7:08
a4a93-Feb-07 7:08 
AnswerRe: wrappers Pin
Christian Graus3-Feb-07 9:49
protectorChristian Graus3-Feb-07 9:49 
Questionaccess application settings from code in windows settings Pin
red60mans3-Feb-07 6:48
red60mans3-Feb-07 6:48 
QuestionDuplicate resources... Pin
Shy Agam3-Feb-07 4:53
Shy Agam3-Feb-07 4:53 
Questionhow can recognize file extension for download Pin
B.A3-Feb-07 4:06
B.A3-Feb-07 4:06 
AnswerRe: how can recognize file extension for download Pin
Rizawn3-Feb-07 4:33
Rizawn3-Feb-07 4:33 
AnswerRe: how can recognize file extension for download Pin
B.A3-Feb-07 5:24
B.A3-Feb-07 5:24 
GeneralRe: how can recognize file extension for download Pin
Rizawn4-Feb-07 1:16
Rizawn4-Feb-07 1:16 
JokeRe: how can recognize file extension for download Pin
B.A4-Feb-07 3:50
B.A4-Feb-07 3:50 
GeneralRe: how can recognize file extension for download Pin
VirtualVoid.NET6-Feb-07 3:53
VirtualVoid.NET6-Feb-07 3:53 
QuestionThread confusion !! Pin
Hussam Fattahi3-Feb-07 3:30
Hussam Fattahi3-Feb-07 3:30 

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.