Click here to Skip to main content
15,914,444 members
Home / Discussions / C#
   

C#

 
AnswerRe: R/W in Notepad Pin
Nadia Monalisa13-Sep-06 6:55
Nadia Monalisa13-Sep-06 6:55 
QuestionCreate Instance of an Application Pin
EscKey200413-Sep-06 6:18
EscKey200413-Sep-06 6:18 
AnswerRe: Create Instance of an Application Pin
Ed.Poore13-Sep-06 6:49
Ed.Poore13-Sep-06 6:49 
AnswerRe: Create Instance of an Application Pin
Judah Gabriel Himango13-Sep-06 6:49
sponsorJudah Gabriel Himango13-Sep-06 6:49 
GeneralRe: Create Instance of an Application Pin
EscKey200413-Sep-06 7:34
EscKey200413-Sep-06 7:34 
GeneralRe: Create Instance of an Application Pin
Judah Gabriel Himango13-Sep-06 8:07
sponsorJudah Gabriel Himango13-Sep-06 8:07 
GeneralRe: Create Instance of an Application Pin
EscKey200413-Sep-06 8:14
EscKey200413-Sep-06 8:14 
Questionbit operations question for binary>decimal Pin
mmatteson13-Sep-06 6:14
mmatteson13-Sep-06 6:14 
i just started a socket application that recieves UDP data. The data that i am recieving is a netflow packet from cisco devices. to learn how to do this i have been searching the forums and looking at other people's code for reference. some code that i came across was the following. pretty much what you do is, passed a byte[2048] to the procedure ToUInt and specify the starting point to get the datafield in the byte and the length from that starting position to get. the first field in the packet is the version field which starts at position 0 and is 16 bits long. so you would end up passing to the following code the byte[2048] of your data buffer, 0 for your offset and 16 for your length. i understand mostly all of the code except that part there the Shift Right occurs and the ANDing against 0x0001.

b is 10, and then after the bitwise operations is it 5. which is the correct version number for the netflow packet that my application recieved.


public static uint ToUInt(byte[] datagram, int offset, int length) {
uint total = 0;
int byte_index;
int bit_offset;
int bit;
byte b;

for ( int i = 0; i < length; i++ ) {
bit_offset = (offset+i) % 8;
byte_index = (offset+i-bit_offset) / 8;
b = datagram[byte_index];
bit = (int)(b >> (7 - bit_offset));
bit = bit & 0x0001;

if ( bit > 0 ) {
total += (uint)Math.Pow(2,length-i-1);
}
}

return total;
}


i modified the code to print to a console the values of each variable during each iteration of the loop. here are the values.

i bit_offset byte_index b bit total
0 0 0 0 0 0
1 1 0 0 0 0
2 2 0 0 0 0
3 3 0 0 0 0
4 4 0 0 0 0
5 5 0 0 0 0
6 6 0 0 0 0
7 7 0 0 0 0
8 0 1 5 0 0
9 1 1 5 0 0
10 2 1 5 0 0
11 3 1 5 0 0
12 4 1 5 0 0
13 5 1 5 1 4
14 6 1 5 0 4
15 7 1 5 0 5

i relize that the byte_index is just a counter for how many bits you have iterated through. once you went through 8 bits, incriment the byte index by 1. since the length is 16, that is two bytes and that would account for 0, and 1. i is just the counter set to the length of 16. i don't understand the B, bit, and total values. could someone explain the logic behind this to me?
AnswerRe: bit operations question for binary&gt;decimal Pin
Guffa13-Sep-06 9:20
Guffa13-Sep-06 9:20 
GeneralRe: bit operations question for binary&gt;decimal Pin
mmatteson29-Sep-06 10:51
mmatteson29-Sep-06 10:51 
QuestionVB SCRIPT issue : called from C# Pin
Nadia Monalisa13-Sep-06 5:56
Nadia Monalisa13-Sep-06 5:56 
AnswerRe: VB SCRIPT issue : called from C# Pin
Nader Elshehabi13-Sep-06 9:07
Nader Elshehabi13-Sep-06 9:07 
GeneralRe: VB SCRIPT issue : called from C# Pin
Nadia Monalisa13-Sep-06 9:23
Nadia Monalisa13-Sep-06 9:23 
GeneralRe: VB SCRIPT issue : called from C# Pin
Nader Elshehabi13-Sep-06 9:48
Nader Elshehabi13-Sep-06 9:48 
QuestionStoring connection string in CODE instead of App.Config ! , POSSIBLE ? Pin
Nadia Monalisa13-Sep-06 5:46
Nadia Monalisa13-Sep-06 5:46 
AnswerRe: Storing connection string in CODE instead of App.Config ! , POSSIBLE ? Pin
Nader Elshehabi13-Sep-06 6:04
Nader Elshehabi13-Sep-06 6:04 
GeneralRe: Storing connection string in CODE instead of App.Config ! , POSSIBLE ? Pin
Nadia Monalisa13-Sep-06 6:22
Nadia Monalisa13-Sep-06 6:22 
GeneralRe: Storing connection string in CODE instead of App.Config ! , POSSIBLE ? Pin
Nader Elshehabi13-Sep-06 7:32
Nader Elshehabi13-Sep-06 7:32 
GeneralRe: Storing connection string in CODE instead of App.Config ! , POSSIBLE ? Pin
Nadia Monalisa13-Sep-06 7:37
Nadia Monalisa13-Sep-06 7:37 
GeneralRe: Storing connection string in CODE instead of App.Config ! , POSSIBLE ? Pin
Nadia Monalisa13-Sep-06 7:44
Nadia Monalisa13-Sep-06 7:44 
GeneralRe: Storing connection string in CODE instead of App.Config ! , POSSIBLE ? Pin
Nader Elshehabi13-Sep-06 8:40
Nader Elshehabi13-Sep-06 8:40 
GeneralRe: Storing connection string in CODE instead of App.Config ! , POSSIBLE ? Pin
Nadia Monalisa13-Sep-06 9:37
Nadia Monalisa13-Sep-06 9:37 
GeneralRe: Storing connection string in CODE instead of App.Config ! , POSSIBLE ? Pin
Nader Elshehabi13-Sep-06 10:12
Nader Elshehabi13-Sep-06 10:12 
GeneralRe: Storing connection string in CODE instead of App.Config ! , POSSIBLE ? Pin
Nadia Monalisa13-Sep-06 10:24
Nadia Monalisa13-Sep-06 10:24 
GeneralRe: Storing connection string in CODE instead of App.Config ! , POSSIBLE ? Pin
Nader Elshehabi13-Sep-06 10:37
Nader Elshehabi13-Sep-06 10:37 

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.