|
I have 2 binary numbers, NO. I have 1 binary number...
01010011
Now, how would I convert that to hex? I.E. (53)
convert this bin number...
11111111
into this... (FF)??
/\ |_ E X E GG
|
|
|
|
|
Convert class may be useful for you. If not, maybe you have to write your own convertor
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
Hex numbers are composed of 4 bits, since 1111 = F so you need to split the bitstring into pieces of 4 bits wide. Then you need to find the decimal value of these bits. Next you look if the value is < 10 if not then you will need to assign a letter A-F to the value and append that to your result. Else you can simply convert the number to text and append that to your result. The problem you will probably ecounter is that the string is not big enough to split into pieces that all are 4 bits wide. You can simply solve that with a check if(bitString.Length % 4 != 0) .... this will indicate that the string is not long enough!
ArrayList strings;<br />
string result = "";<br />
int tempValue;<br />
int counter;<br />
<br />
strings = new ArrayList();<br />
<br />
for(int i = 0; i < bitString.Length; i += 4)<br />
{<br />
strings.Add(bitString.Substring(i,4)); <br />
}<br />
<br />
<br />
foreach(string bits in strings)<br />
{<br />
tempValue = 0;<br />
counter = 1;<br />
<br />
for(int j = bits.Length-1; j > 0; j--)<br />
{<br />
if(bits[j] == '1')<br />
{<br />
tempValue += counter;<br />
}<br />
<br />
counter *= 2;<br />
} <br />
<br />
if(tempValue < 10)<br />
{ <br />
result += tempValue.ToString();<br />
}<br />
else<br />
{<br />
switch(tempValue)<br />
{<br />
case 10:<br />
result += "A";<br />
break;<br />
case 11:<br />
result += "B";<br />
break;<br />
}<br />
}
I am sorry for you if there are any mistakes in the code above. This code was written in approx. 30 seconds and not tested. Good luck!!
Greetings....
|
|
|
|
|
When I right-click on a node in my treeview, is it possible to find out which node I clicked? The TreeView.SelectedNode wont work because apparently, you need to left click to select a node.
So, any pointers?
God, I pity me! - Phoncible P. Bone
If I end up Windows ME someone is going to be hurting. - One of the answers to a question for What OS are you
|
|
|
|
|
Hi,
The first thing that you need to do is add an oncontextmenu statement on your treeview control there are 2 ways to do that.
1) Go into Design view and add this statement to the treeview
oncontextmenu="javascript: showMenu(this); return false;"
2) Go into your CS code and add an attribute to use the function below
this.TreeView1.Attributes.Add("oncontextmenu","showMenu(this)");
Now here is some code:
function showMenu(Item)
{
var NodeSelected = document.getElementById(Item.id).getTreeNode(event.treeNodeIndex);
var NodeLevel = new Number(event.treeNodeIndex)
var ParentNode = document.getElementById(Item.id).getTreeNode(event.treeNodeIndex).getParent();
var NodeType = "";
var strTreeNodeIndex = "";
strTreeNodeIndex = new String(NodeSelected.getNodeIndex());
NodeType = new String(NodeSelected.getAttribute("type") );
NodeType = NodeType.toUpperCase();
alert("The Node type is " + NodeType + " The Node text is " + NodeSelected.getAttribute("text") );
}
this should get you started
|
|
|
|
|
Um, that'd work for ASP.NET, but he never mentioned that he was using ASP.NET. And, since this is the C# forum and not the ASP.NET forum, you should take that into consideration.
The answer in Windows Forms uses hit tracking. Handle the TreeView.MouseUp event. In the handler, check to see if the right mouse button was clicked (don't worry about lefties - Windows swaps the left and right mouse messages so developers don't have to worry about it) using Control.MouseButtons == MouseButtons.Right . If that condition is true, get the position of the mouse click from the event arguments and get the node that was clicked using TreeView.GetNodeAt after translating the point accordingly since the X and Y coordinates of the click are relative to the form.
Example:
public class MyForm : Form
{
private TreeNode activeNode;
private void myTreeView_MouseUp(object sender, MouseEventArgs args)
{
if (MouseButtons == MouseButtons.Right)
{
Point p = new Point(args.X, args.Y);
p = this.myTreeView.PointToClient(p);
this.activeNode = myTreeView.GetNodeAt(p);
}
}
}
Then just use the activeNode field for your context menu items' Click handlers or in the context menu's Popup event handler (to enable, disable, or change menu items).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks, this is exactly what I needed!
God, I pity me! - Phoncible P. Bone
If I end up Windows ME someone is going to be hurting. - One of the answers to a question for What OS are you
|
|
|
|
|
Ummm...Thanks for the prompt reply. I probably should've said I was using Windows Form
God, I pity me! - Phoncible P. Bone
If I end up Windows ME someone is going to be hurting. - One of the answers to a question for What OS are you
|
|
|
|
|
My fault sorry, I guess I over looked that one. Oh well, now you know how to do it on the web to
Will
|
|
|
|
|
It's no prob. And you never know when I might need it one day
God, I pity me! - Phoncible P. Bone
If I end up Windows ME someone is going to be hurting. - One of the answers to a question for What OS are you
|
|
|
|
|
myLib have some code :
<br />
this.url = "myurl";<br />
userid = "myid";<br />
passwd = "mypwd";<br />
comment = "cat/etc/resolv.conf";<br />
<br />
[System.Web.Services.Protocols.SoapDocumentMethodAttribute<br />
("",RequestNamespace="urn:execute",ResponseNamespace="urn:myLib",Use=<br />
System.Web.Services.Description.SoapBindingUse.Encoded, ParameterStyle=<br />
System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]<br />
<br />
public string execute(string userid, string passwd, string command)<br />
{<br />
object [] results = this.Invoke("execute",new object[] { userid, passwd, command });<br />
return ((string)(results[0]));<br />
}<br />
and my application has code :
<br />
string result = myLib.execute(userid, passwd, command.Text);<br />
I don't understand [System.Web.Services.Protocols.SoapDocumentMethodAttribute
("",RequestNamespace="urn:execute",ResponseNamespace="urn:myLib",Use=
System.Web.Services.Description.SoapBindingUse.Encoded, ParameterStyle=
System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] does and somebody can explain that , what 'this.Invoke("execute", new object[] {userid, passwd, command));' do???
please help me?? thanks
|
|
|
|
|
Is it trying to invoke a web method of a given URL and given namespace?
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
hi,
i want to do insert statement in access db. but, i found somethings wrong.
would anyone give a helping hand?
here is the code:
String strCmd = new String(' ', 1024);
strCmd = "insert into profile(id, interval, address) values(1,1, \"tuen moon\")";
OleDbCommand cmd = new OleDbCommand(strCmd, conn);
int result = cmd.ExecuteNonQuery();
there is a exception.
"Syntax error in INSERT INTO statement"
i can't see any syntax error on my sql statement...
anyone can help? is it related to MS Access?
thanks,
jim
|
|
|
|
|
|
bool switchB=true;
private void button1_Click(object sender, System.EventArgs e)
{
if(switchB==true)
{
<code>
switchB=false;
}
else if(switchB==false)
{
}
}
I have a set of 7 buttons, numbered from 0-7, right to left, and all their text set to "0".
now, all of the button's onclicks go to the above method...
As you can see, inside the for loop... Now all I need it to do is this...
Change the text of whatever (of the 8) buttons were clicked.
/\ |_ E X E GG
|
|
|
|
|
this works:
Button btn = null;
if(switchB==true){
<code> btn </code>= (Button)<code>sender</code>;
<code> btn</code>.Text = "<code>Persian Gulf</code>";
switchB = false;
}
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
Ok, cool. That worked. I didn't know you could declare your own Button, like you can a variable...
I'm confused... whatever... thanks again.
/\ |_ E X E GG
|
|
|
|
|
Have you ever programmed before? You can declare a variable of any type you want. This is evident in every programming language. You can use generics or types for variables, fields, properties, function parameters, and whatever you choose.
Some languages like JavaScript/JScript may declare a variable type as var (a generic), but even it has a type - the type of whatever function or object filled it (like var d = new Date(); - d is now of type Date )
Similarily, the same is true in .NET (and Java and MFC). Every class in those frameworks (and some others) derives from Object (or CObject , etc.) If you assign a different type to a generic variable, the type is still that of the type you assigned it:
object o = new Button();
o is actually of type Button , even though it is declared as an Object . You could also declare that variable as a Button , or a Control , or any base class of the Button type. Casting that object doesn't change it - merely gives you access to the methods and properties defined for that class (or inherited by base classes). For example, it wouldn't matter if the variable was declared as a Object or a Button . If you called the ToString method, the method that is called is the one declared on Button because it overrided the method of a base class. This is typically (shall I say, "standard") object-oriented programming (OOP).
I recommend you pick up a good book on .NET programming, or even just OO programming. Looking at a lot of the questions that you've posted, you should also browse around the base class library (BCL) documentation that was installed with the .NET Framework SDK and Visual Studio .NET.
This isn't a slam, but a reminder that research is only half (if not more) of development. Guessing and getting other people to do the work is not going to teach you anything. Browsing around the .NET Framework library will at least familiarize you with what is available so you have some idea of what you could use in a given problem so you don't have to reinvent the wheel. A good book on OO will help you design efficient and effective code.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
|
could you not add a universal handler for all of the buttons? then use
sender.GetType().Name="blabla"
Csharp™ the coder formally known as dynamic
Me.twins.duedate = DateTime.Now.AddDays(+17).ToLongDateString Me.Birthday = DirectCast(Me.twins.DueDate, DateAndTime.SameDay)
|
|
|
|
|
here's a quick example i built for you...
<br />
private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
foreach(Control btn in this.Controls)<br />
{<br />
if(btn.GetType().Name=="Button")<br />
{<br />
btn.Click+=new System.EventHandler(this.Clicker);<br />
}<br />
}<br />
}<br />
<br />
private void Clicker(object sender, System.EventArgs e)<br />
{<br />
Button b=(Button)sender;<br />
MessageBox.Show(b.Name);<br />
}
hope it helps
Csharp™ the coder formally known as dynamic
Me.twins.duedate = DateTime.Now.AddDays(+17).ToLongDateString Me.Birthday = DirectCast(Me.twins.DueDate, DateAndTime.SameDay)
|
|
|
|
|
no no no thanks... I HAVE IT!
/\ |_ E X E GG
|
|
|
|
|
Hello, I have a slight problem. I have an application written in Java, but i'm rewriting it to C# currently. Now i've run into some problems since some parts of the save procedure used java serialization (of a hashtable).
Of course I need to be able to still read files made with the java version, but how can this be done? basically I would need to decode the serialized java object. Is there any documentation to be found on this subject?
does anyone have an idea?
|
|
|
|
|
misterbear wrote:
does anyone have an idea?
Yap: check on Sun's site if there is any doc on how the standard hashtables are serialized!
Once you know that,
open the files, and read them into a C# Hashtable as needed.
HTH,
F.O.R.
|
|
|
|
|
Keep in mind that the objects in the hashtable were also serialized. For the most part, if you were to use simply objects in a Java hashtable and save that to a file (I'm thinking just a simple test class with String members), you could also reverse engineer it. That wouldn't be so hard using your favorite hex editor. Depending on the complexity of the objects within it, though, that's another story.
If nothing else and worse comes to worse, you could always use the JNI concepts I cover in my article, Embedding .NET Controls in Java. The content of the article doesn't apply so much as the concept does - using JNI to bridge the gab between .NET and Java. A JNI Win32 DLL (not a managed assembly - Java won't know how to load it) to use Java calls to deserialize a hashtable and pass the members to .NET, or could even use late binding and the unmanaged CLR methods to get your .NET assembly to serialize the hashtable. Basically, this idea would be a one-time conversion utility (I recommend not overriding the old file though, or you should at least back it up).
Obviously, deserializing the hashtable would be preferred (and most likely not hard to do), but the latter idea could be handy in a worse-case scenario.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|