|
Can you explain it a bit more. What is n?
|
|
|
|
|
I didn't notice you have named the integer. n is the UserId
Eslam Afifi
|
|
|
|
|
I think this would work:
int num = 1000;
byte one = (byte)(0x00FF & num);
byte two = (byte) ((0xFF00 & num) >> 8);
So, you know 1000 is 03E8.
If you AND this with 0xFF00 then you get left with 0300 we then RIGH SHIFT it by 8 which leaves us with just 03
For the other half we AND the original number with 0x00FF which leaves us with 0x00E8
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
You don't have to AND with 1
Eslam Afifi
|
|
|
|
|
Exception System.OverflowException was thrown in debuggee:
Arithmetic operation resulted in an overflow.
Apparently I do.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
int n = 1000;
System.Diagnostics.Debug.WriteLine((byte)n);
System.Diagnostics.Debug.WriteLine((n >> 8));
This compiles and runs fine.
Eslam Afifi
|
|
|
|
|
But this doesn't:
int n = 1000;
byte i = (byte)n;
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
No, it does.
int n = 1000;
byte i = (byte)n;
System.Diagnostics.Debug.WriteLine(i);
Eslam Afifi
|
|
|
|
|
Huh, what version of the framework are you using?
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
I targeted 2.0, 3.0 and 3.5 and it works with all of them. I don't know why you got that exception but ANDing with 1 just gives you another integer and it's just an extra operation.
Eslam Afifi
|
|
|
|
|
Weird, actually a byte can only go from 0-255, which is why when I try to cast the int (1000) to a byte I get the overflow exception, since 1000 is too big to fit into 255.
I'm not sure why our results vary but, there it is
EDIT: I am using SharpDevelop, if you're using VS then perhaps it's changing something that SD isn't.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Well, I've just got that thought. In my Visual Studio, the "Check for arithmetic overflow/underflow" option is not enabled. I'm pretty sure that's the reason. The compiler neglects the overflow (data loss which is fine in this case). But I’m curious; the code you provided does the same (casting from int to byte if I’m not wrong).You're right. ANDing with 1 removes possible overflow.
Eslam Afifi
modified on Monday, June 16, 2008 11:32 PM
|
|
|
|
|
Thanks for all the reply. But I should get the value as
byArrData[4] = E8;
byArrData[5] = 03;
If i do
byArrData[4] = (byte)((unUserID) >> 8);
byArrData[5] = (byte)(unUserID);
I'll get 232 & 03.
How should I get the hex value? Please help
|
|
|
|
|
Actually, everything is represented in binary. A byte is 8 bits an you're storing the values in byte[]
232 is 11101000 in binary. The way you see it (decimal, binary, octal, hexadecimal ...) doesn't matter because it's actually stored in binary.
If you want to get a string representing the value in hexadecimal, use ((byte)(unUserID >> 8)).ToString("X") // this returns a string
Eslam Afifi
|
|
|
|
|
When I tried that "Cannot convert from string to byte" error is coming. Any solution.
|
|
|
|
|
|
I would require the code/methods for detecting different firewalls installed on a system. Though I have done this for Windows Firewall, I would require help in detecting other firewalls installed.
-----Have A Nice Day-----
|
|
|
|
|
I think you can do this with WMI, You should find a reference on that to help you.
See here[^], read the question on "How does Windows Security Center detect third-party products and their status?"
Simon
|
|
|
|
|
I have to switch between forms in my application. I don't need classical MDI look and feel. So I created all my forms as controls. Created a single form with a panel and the navigation panel. When items are clicked on the navigation panel, I am adding corresponding control to the panel. It works for the first time, but when I click 2nd time on the button, it's not showing. So I called Panel.Controls.Clear() before I add controls. It is working fine now.
Is this approach correct ? Or is there any other efficient methods available ? Here is sample code
this.panel1.Controls.Clear();
form1.Dock = DockStyle.Fill;
form1.BringToFront();
form1.Visible = true;
this.panel1.Controls.Add(form1);
NOTE : form1 is a user control here and not a form.
Any ideas will be helpful.
|
|
|
|
|
You should probably just add all the usercontrols to the panel1.controls collection at the beginning, then show and hide the usercontrols (by setting the visibility) as necessary. This will save you clearing the collection and recreating each usercontrol each time you show it.
Simon
|
|
|
|
|
Hello everyone,
From the IL for the following code, seems there is default constructor for both value and reference types which accepts null argument? Are they added by CLR directly (from .locals init IL statement)?
class Program
{
struct Foo
{
int abc;
}
class Goo
{
public int abc;
}
static void Main(string[] args)
{
Foo f;
Goo g;
return;
}
}
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
.maxstack 0
.locals init (
[0] valuetype TestStruct1.Program/Foo f,
[1] class TestStruct1.Program/Goo g)
L_0000: nop
L_0001: br.s L_0003
L_0003: ret
}
thanks in advance,
George
|
|
|
|
|
Yes, according to the spec[^].
"All value types implicitly declare a public parameterless instance constructor called the default constructor."
|
|
|
|
|
Thanks Senthil,
1. For value type, even if we provide a customized constructor, there is also the default one (co-exist with customized one)?
2. For reference type, there is also a default constructor even if we provide a customized one (co-exist with default one)?
regards,
George
|
|
|
|
|
George_George wrote: For value type, even if we provide a customized constructor, there is also the default one (co-exist with customized one)?
NO
George_George wrote: For reference type, there is also a default constructor even if we provide a customized one (co-exist with default one)?
NO
|
|
|
|
|
ForumExpertOnLine wrote: George_George wrote:
For value type, even if we provide a customized constructor, there is also the default one (co-exist with customized one)?
NO
Wrong - the default constructor exists, whether you create a overloaded one or not.
struct S
{
int x;
public S(int x)
{
this.x = x;
}
public int X
{
get { return x; }
}
}
class Program
{
static void Main(string[] args)
{
S s = new S();
Console.WriteLine(s.X);
}
}
|
|
|
|