Click here to Skip to main content
15,904,348 members
Home / Discussions / C#
   

C#

 
GeneralRe: Application.Exit Pin
Adam Goossens7-Jan-05 1:21
Adam Goossens7-Jan-05 1:21 
GeneralRe: Application.Exit Pin
pcJuice7-Jan-05 13:51
pcJuice7-Jan-05 13:51 
QuestionHow much exception handling is to much? Pin
KevinMac6-Jan-05 6:26
KevinMac6-Jan-05 6:26 
AnswerRe: How much exception handling is to much? Pin
Andy Brummer6-Jan-05 7:57
sitebuilderAndy Brummer6-Jan-05 7:57 
GeneralRe: How much exception handling is to much? Pin
Heath Stewart6-Jan-05 13:52
protectorHeath Stewart6-Jan-05 13:52 
GeneralRe: How much exception handling is to much? Pin
Andy Brummer6-Jan-05 16:06
sitebuilderAndy Brummer6-Jan-05 16:06 
GeneralAnother C to c# help.... Pin
Blubbo6-Jan-05 5:48
Blubbo6-Jan-05 5:48 
GeneralRe: Another C to c# help.... Pin
Heath Stewart6-Jan-05 13:41
protectorHeath Stewart6-Jan-05 13:41 
Hex != base64. Hex is base16, which is obviously not base64. To hex-encode integers you can use their IFormattable.ToString implementation. This could be done like so:
int value = 1989;
string hex = "0x" + value.ToString("x4");
This will hex-encode 1989 into a four-digit hexadecimal representation to look like "0x07c5".

You don't need to conver to hex, however. Hex is only a representation of numbers. Your tempvar in the C code will contain the bytes {0x31, 0x39, 0x38, 0x39}. Those are strings, though - they're numberic expressions for the ANSI characters (since you're using a char array, they are only 8-bit character using the codepage you specify when compiling (default of system codepage).

Also keep in mind that a char* or char[] is a string. A string is just an array of characters. So if dataArray was a byte[] array like in your example (meaning ANSI text, not Unicode like .NET uses to encode stored strings), then you'll need to convert your string "1989" to a byte[] array using ASCIIEncoding and compre the buffers at that offset:
//#!csc.exe /t:exe Test.cs
//
 
using System;
using System.Text;
 
class Test
{
  static void Main()
  {
    byte[] text = Encoding.ASCII.GetBytes("1989");
    byte[] dataArray = new byte[256];
 
    int i = 0xc0;
    dataArray[i++] = 0x31;
    dataArray[i++] = 0x39;
    dataArray[i++] = 0x38;
    dataArray[i++] = 0x39;
 
    bool found = true;
    for (i=0; i<4; i++)
      if (dataArray[0xc0 + i] != text[i])
      found = false;
 
    Console.WriteLine(found);
  }
}
An easier way is to just convert the 4 elements starting at offset 0xc0 from dataArray into a string and compare it:
//#!csc.exe /t:exe Test.cs
//
 
using System;
using System.Globalization;
using System.Text;
 
class Test
{
  static void Main()
  {
    byte[] dataArray = new byte[256];
 
    int i = 0xc0;
    dataArray[i++] = 0x31;
    dataArray[i++] = 0x39;
    dataArray[i++] = 0x38;
    dataArray[i++] = 0x39;
 
    byte[] text = new byte[4];
    Array.Copy(dataArray, 0xc0, text, 0, 4);
 
    string s = Encoding.ASCII.GetString(text);
    bool found = string.Compare("1989", s, true,
      CultureInfo.InvariantCulture) == 0;
    Console.WriteLine(found);
  }
}
You should read up on string encoding for more information. Also note that compilers treat various numerical expressions the same, so:
0xC0 == 192 == \300
They're all just different representations of the same numbers, so don't confuse hex-encoded values as string to compare.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralDisabled Button still accepts presses Pin
mikey_g6-Jan-05 5:45
mikey_g6-Jan-05 5:45 
GeneralRe: Disabled Button still accepts presses Pin
Nick Parker6-Jan-05 7:04
protectorNick Parker6-Jan-05 7:04 
GeneralRe: Disabled Button still accepts presses Pin
mikey_g6-Jan-05 23:33
mikey_g6-Jan-05 23:33 
GeneralXML Bulk Loader (SQLXML 3.0) Pin
exhaulted6-Jan-05 3:43
exhaulted6-Jan-05 3:43 
GeneralRe: XML Bulk Loader (SQLXML 3.0) Pin
perlmunger6-Jan-05 5:37
perlmunger6-Jan-05 5:37 
GeneralInfragistics UltraCalendarInfo control Pin
eliea6-Jan-05 1:45
eliea6-Jan-05 1:45 
GeneralRe: Infragistics UltraCalendarInfo control Pin
Nick Parker6-Jan-05 6:50
protectorNick Parker6-Jan-05 6:50 
Generalmodifying xml field data's using c# Pin
dhol6-Jan-05 1:42
dhol6-Jan-05 1:42 
GeneralRe: modifying xml field data's using c# Pin
perlmunger6-Jan-05 5:43
perlmunger6-Jan-05 5:43 
GeneralRe: modifying xml field data's using c# Pin
dhol6-Jan-05 16:38
dhol6-Jan-05 16:38 
GeneralRe: modifying xml field data's using c# Pin
perlmunger7-Jan-05 6:27
perlmunger7-Jan-05 6:27 
GeneralRe: modifying xml field data's using c# Pin
dhol7-Jan-05 17:05
dhol7-Jan-05 17:05 
GeneralMethod return Value Pin
webhay5-Jan-05 23:43
webhay5-Jan-05 23:43 
GeneralRe: Method return Value Pin
Stefan Troschuetz5-Jan-05 23:59
Stefan Troschuetz5-Jan-05 23:59 
GeneralRe: Method return Value Pin
haimlz6-Jan-05 1:02
haimlz6-Jan-05 1:02 
GeneralRe: Method return Value Pin
Salil Khedkar6-Jan-05 1:07
Salil Khedkar6-Jan-05 1:07 
GeneralXmlDocument Write problems and Add Identation Help! Pin
Chua Wen Ching5-Jan-05 23:40
Chua Wen Ching5-Jan-05 23:40 

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.