Click here to Skip to main content
15,867,704 members
Home / Discussions / C#
   

C#

 
GeneralPacket Capture Project Pin
firat kocak20-May-03 6:43
firat kocak20-May-03 6:43 
QuestionReading a Random Access file.. how to parse bytes? Pin
dazinith20-May-03 5:03
dazinith20-May-03 5:03 
AnswerRe: Reading a Random Access file.. how to parse bytes? Pin
firat kocak20-May-03 6:26
firat kocak20-May-03 6:26 
GeneralRe: Reading a Random Access file.. how to parse bytes? Pin
dazinith20-May-03 7:22
dazinith20-May-03 7:22 
GeneralRe: Reading a Random Access file.. how to parse bytes? Pin
dazinith20-May-03 7:43
dazinith20-May-03 7:43 
GeneralRe: Reading a Random Access file.. how to parse bytes? Pin
dazinith20-May-03 8:26
dazinith20-May-03 8:26 
GeneralRe: Reading a Random Access file.. how to parse bytes? Pin
leppie20-May-03 11:37
leppie20-May-03 11:37 
GeneralRe: Reading a Random Access file.. how to parse bytes? Pin
firat kocak20-May-03 20:42
firat kocak20-May-03 20:42 
way - 1 : it may be unsafe. but unsafe doesn't mean that it is really unsafe Smile | :) . it means that "be carefulu on using unsafe, if you incorrectly use it you may crash the system LOL ). bu if you want your code pure Managed then you are wright.

way - 2 : When you wrote an int value to a file or a memory it is written as fallows,
first low part of the value and then the high part.
2 bytes value (byte0-byte1) byte1 and then byte2
4 bytes value (byte0-byte1-byte2-byte3) byte3 and then byte2 and then byte1 and latest byte0

So you must know the layout of the value of the byte array you try to read from a file. so lıater you can write the function below to read different types of value from a byte array

public static bool GetBool( byte [] MyData , int index )
{
return ( MyData[ index ] == 0 ? false : true );
}

public static short GetShort( byte [] MyData , int index )
{
short s = 0;

s = (short) ( ( ( int ) MyData[ index + 1 ] ) << 8 );
s += (short ) Mydata[ index ];

return s;
}

public static int GetInt( byte [] MyData , int index )
{
int s = 0;

s = ( ( int ) MyData[ index + 3 ] ) << 24;
s = ( ( int ) MyData[ index + 2 ] ) << 16;
s = ( ( int ) MyData[ index + 1 ] ) << 8;
s += ( int ) Mydata[ index ];

return s;
}

public static string GetString( byte [] MyData , int index , int len )
{
string s;

s = Encoding.ASCII.GetString( MyData , index , len );

return s;
}

Before converting date values from a byte array, you must know what format it has. Because i don't know the format, so i cann't help you

cheers,

Doing something is better than doing nothing. So ... Move !
AnswerRe: Reading a Random Access file.. how to parse bytes? Pin
Nathan Blomquist21-May-03 1:47
Nathan Blomquist21-May-03 1:47 
GeneralAutocompletion in DropDown ComboBox Pin
Braulio Dez20-May-03 0:22
Braulio Dez20-May-03 0:22 
GeneralRe: Autocompletion in DropDown ComboBox Pin
dazinith20-May-03 5:17
dazinith20-May-03 5:17 
GeneralRe: Autocompletion in DropDown ComboBox Pin
Braulio Dez20-May-03 5:34
Braulio Dez20-May-03 5:34 
GeneralRe: Autocompletion in DropDown ComboBox Pin
Braulio Dez20-May-03 5:44
Braulio Dez20-May-03 5:44 
GeneralRe: Autocompletion in DropDown ComboBox Pin
Richard Deeming21-May-03 8:20
mveRichard Deeming21-May-03 8:20 
GeneralRe: Pens &amp; Brushes Pin
Jon Newman20-May-03 4:30
Jon Newman20-May-03 4:30 
GeneralRe: Pens &amp; Brushes Pin
Jon Newman20-May-03 5:41
Jon Newman20-May-03 5:41 
GeneralRe: Pens &amp; Brushes Pin
Arun Bhalla20-May-03 18:58
Arun Bhalla20-May-03 18:58 
GeneralRe: Pens &amp; Brushes Pin
leppie20-May-03 8:08
leppie20-May-03 8:08 
GeneralRe: Pens &amp; Brushes Pin
Marc Clifton21-May-03 4:10
mvaMarc Clifton21-May-03 4:10 
GeneralRe: Pens &amp; Brushes Pin
leppie21-May-03 7:01
leppie21-May-03 7:01 
General[Question] about SNMP Manager Pin
yoonbs19-May-03 23:53
yoonbs19-May-03 23:53 
GeneralRe: [Question] about SNMP Manager Pin
firat kocak20-May-03 6:31
firat kocak20-May-03 6:31 
GeneralRe: [Question] about SNMP Manager Pin
yoonbs20-May-03 13:33
yoonbs20-May-03 13:33 
GeneralRe: [Question] about SNMP Manager Pin
firat kocak20-May-03 23:12
firat kocak20-May-03 23:12 
GeneralRe: [Question] about SNMP Manager Pin
yoonbs22-May-03 16:31
yoonbs22-May-03 16:31 

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.