|
Hi Joe
You can do this like
string str = "0000000000000001";
byte[] bb = System.Text.ASCIIEncoding.ASCII.GetBytes(str);
string str2 = System.Text.ASCIIEncoding.ASCII.GetString(bb);
MessageBox.Show(str + "\r\n" + str2 );
Regards
Mamun
|
|
|
|
|
Dear friend thanks for replay....
that's good idea but You see
shiplu_2050 wrote: System.Text.ASCIIEncoding.ASCII.GetBytes(str);
will return byte array size of 16 ...
i want to make to as 2 bytes ... and form 2 bytes to string.
thank you
|
|
|
|
|
If I read your messages correctly, you want to take in a string of 16 '0' or '1' characters, and convert them to two bytes, then convert the two bytes back to s string?
If so, then the first thing you need to look at is the "<<" operator. This shifts bits a number of places to the left within a byte, int or whatever.
So you would:
For each character in string, convert it to a byte (0 or 1) depending on whether it was '0' or '1'.
Shift that bit into a byte until the byte is full. Save the byte, and move on for the next.
Re-assembling the string from your bytes is the reverse of this, and is probably best done with a method to convert a byte to an 8 character string, used twice.
Honestly, it is quicker to write the code, than to describe it!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
"Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"
|
|
|
|
|
Hi,
this is not related to character set encodings at all, it is either simple arithmetic, or using the appropriate conversion operations.
if you're sure the string is limited to 16 (or 32 or 64) binary digits, you can use code similar to this:
ushort sh=Convert.ToUInt16(binaryString, 2);
byte hi=(byte)(sh>>8);
byte lo=(byte)sh;
The inverse operation would be:
ushort sh=(ushort)((hi<<8) + lo);
binaryString=Convert.ToString(sh, 2);
binaryString=binaryString.PadLeft(16, '0');
BTW: you would need a try-catch block to defend against invalid string input.
|
|
|
|
|
Thank you frined ... i got that..
|
|
|
|
|
Hello,
I have an application running more MDI-Child windows.
Each MDI-Child has a graph line in it. Depending on CPU Load it may happen that the main application tells me "Application not responding" with 100% CPU Load.
Is it possible to monitor each MDI-Child's CPU and Memory Load?
I can use the PerformanceCounter for a Process and Threads. But how to determine the Process/Thread of the MDI-Child?
Or is there any possibility to stop an MDI-Child that does no longer respond?
Thank you
|
|
|
|
|
I am creating a plugin for Microsoft Office 2007 applications (Word, Excel, etc.). I need to add my button to the default QAT (Quick Access Toolbar) which is loaded when these applications start. When I set startFromScratch="false" in my XML file the button which I have added in XML doesn't load in QAT.
But it does appear when I set startFromScratch="true" but in that case i end up loosing my default Tabs & QAT features.
Is there any way to add my custom button to default QAT without loosing any default functionalities and features?
Is there any way I can access QAT directly from C# code without having to use XML file for customization of QAT?
Any help regarding this is highly appreciated!
Regards,
Gurdev Singh
|
|
|
|
|
Hi, I was reading how to create a program that crawls website data. one of the example I found was http://www.codeproject.com/KB/IP/Crawler.aspx
but I dont have much resource to crawl everything. In a ideal e-shops you have product page and product details page. what I would like to do is crawl each product page and product details page and only write data that interests me to my database. e.g. product name, product price, etc etc.
could anyone point me to right direction?
Thank you
|
|
|
|
|
So you have used someones article to crawl some web sites, this is good. Now you need to customise the article to meet your needs, so inspect the data as it is crawled and decide what to do with it.
Something along the lines of if it is a product then turn a store flag on and write the data to the database, identify the token that denotes the end of the product information and turn off the store flag.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I am having a little problem. I can get the ip address and hostname and such of my local machine, but what I am trying to do is get the ip address range on the LAN from my local address.
So if my ip is:
10.10.50.2
and the subnet is: 255.255.0.0
How do I get C# to give me the start value (which would be 10.10.0.1) and the end value (which would be 10.10.255.255)?
I don't want to have to have this entered in and want it to go off the local computers information. I can already get the ip address and the subnet.. I'm not unsure how to get the start and end from that information
|
|
|
|
|
Jacob Dixon wrote: How do I get C# to give me the start value (which would be 10.10.0.1) and the end value (which would be 10.10.255.255)?
You have to write the code for that. There is no builtin function to do the math for you. A little Google for "how to calculate ip address range" brings up plenty of results.[^]
|
|
|
|
|
Thanks.. first I was searching for the wrong things.. like what I was typing in.. but I got something that works for me after modifying it
static string GetRange(IPAddress address, IPAddress subnetMask)
{
IPAddress ip = address;
byte[] ipBytes = ip.GetAddressBytes();
byte[] maskBytes = subnetMask.GetAddressBytes();
byte[] startIPBytes = new byte[ipBytes.Length];
byte[] endIPBytes = new byte[ipBytes.Length];
for (int i = 0; i < ipBytes.Length; i++)
{
startIPBytes[i] = (byte)(ipBytes[i] & maskBytes[i]);
endIPBytes[i] = (byte)(ipBytes[i] | ~maskBytes[i]);
}
IPAddress startIP = new IPAddress(startIPBytes);
IPAddress endIP = new IPAddress(endIPBytes);
return startIP.ToString() + " -- " + endIP.ToString();
}
|
|
|
|
|
So you need to thank Dave with a 5 for giving you some of his Google mojo.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I'm trying to get all the files from directory that ends with *.txt only.
The problem is, when i'm doing:
string[] filePaths = Directory.GetFiles(@"C:\MyDir\", "*.txt");
i get also the path.
How can i get only the filename?
(at the end i have to get a string[] because i need to use it as DataSource)
|
|
|
|
|
Example:
string fileName = @"C:\mydir\myfile.txt";<br />
string result;<br />
result = Path.GetFileName(fileName);
Regards.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
tamir901 wrote: i need to use it as DataSource
For a Control? What type?
Have you tried this:
System.IO.FileInfo[] fi = (new System.IO.DirectoryInfo ( "C:\\" )).GetFiles ( "*.txt" ) ;
listBox1.DataSource = fi ;
comboBox1.DataSource = fi ;
checkedListBox1.Items.AddRange ( fi ) ;
domainUpDown1.Items.AddRange ( fi ) ;
I prefer using FileInfo rather than string.
|
|
|
|
|
Thanks...
|
|
|
|
|
I'm a long time VB addict, and I am finally making the switch, and have a quick question. When you're in the code view in VB and you open the drop-down box on the right, you get all the options for that control, so lets say you were in form1_load and clicked the drop down, you would see every available option for form1_whatever. Where the heck is that in C#? I'm going to have to keep VB open just to see the options... hahaha.
Thanks in advance!
|
|
|
|
|
You mean Propety Windows?
You go to view and Select Property Window or Right-Click on any control in Design mode and select Properties. After that you can dock with control
|
|
|
|
|
Nah, like form1_leave form1_click form1.ondragdrop etc, all the events that can be handled in your code...
|
|
|
|
|
ahhh i found it, sorta. Thanks
Theres an events "tab" in the properties window... wierd
|
|
|
|
|
|
You'll find the same thing in VB.NET as well.
What you talking about is specific to the VB.NET code editor. It doesn't show up in the C# version.
|
|
|
|
|
Acording to tutorial (A book: GDI+ Custom Controls With Visual CSharp 2005)I am reading, i have created Custom Control that is divered from Control.
I have overriden OnPaint event, and everytime i put base.OnPaint(e) into event, my IDE and app crashes. IDE crashed due to tempting to render a custom control. I am using VS 2008 SP1 and .NET framework 3.5 SP1.
Why does this happen? Is it required to put inside when diverting from Control class)
Edit: Found the problem. The problem was that I used base.OnPaint() inside event function. I needed to ovridde OnPaint
modified on Sunday, December 6, 2009 2:09 PM
|
|
|
|
|
OnPaint() method actually raises the Paint event. By calling OnPaint() from a method bound to the Paint event, you actually set up an infinite loop causing a stack overflow that crashed the IDE.
|
|
|
|