Click here to Skip to main content
15,918,889 members
Home / Discussions / C#
   

C#

 
QuestionControl Format TextArea Pin
101021066-Oct-06 11:53
101021066-Oct-06 11:53 
QuestionForm Size keeps shrinking! Pin
Rabbit176-Oct-06 11:52
Rabbit176-Oct-06 11:52 
AnswerRe: Form Size keeps shrinking! Pin
Amar Chaudhary6-Oct-06 22:04
Amar Chaudhary6-Oct-06 22:04 
GeneralRe: Form Size keeps shrinking! Pin
Rabbit179-Oct-06 9:20
Rabbit179-Oct-06 9:20 
GeneralRe: Form Size keeps shrinking! Pin
Amar Chaudhary9-Oct-06 12:28
Amar Chaudhary9-Oct-06 12:28 
GeneralRe: Form Size keeps shrinking! Pin
Rabbit179-Oct-06 9:20
Rabbit179-Oct-06 9:20 
GeneralRe: Form Size keeps shrinking! Pin
Rabbit179-Oct-06 10:59
Rabbit179-Oct-06 10:59 
QuestionWhy is the binary number flipped when reading from a byte array? Pin
mmatteson6-Oct-06 10:31
mmatteson6-Oct-06 10:31 
I am reading UDP packets that a router is sending to me. In this example i am reading the "system uptime" field which starts at bit position 64 from the begining of the packet and is a 32 bit field. So the end of the field is calculated to end at 95.
I know that the first byte of this two bit field prints to the console 69 when i Console.WriteLine(buffer[8]). When I do a Convert.ToString(buffer[8],2) I get 101000101 printed on the console. I converted this byte to a decimal number. unfortunatly this is revered! and is being counted LEFT to RIGHT!
When the binary numbers should start from Right to left. the real binary number of 69 is 01000101. which is the mirror opposite of what the console printed. Do you have any idea why this is?

Here is the code that I am looking at.


public static uint Parse(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];

//Writing the datagram to the console and performing the Convert.ToString is where i notice this.

bit = (int)(b >> (7 - bit_offset));
bit = bit & 0x0001;
if ( bit > 0 )
{
total += (uint)Math.Pow(2,length-i-1);
}
}
return total;
}


Is this why there is the shift right and then the AND to somehow fix this issue?
AnswerRe: Why is the binary number flipped when reading from a byte array? Pin
Insincere Dave6-Oct-06 12:51
Insincere Dave6-Oct-06 12:51 
QuestionComputer Generated Random Numbers Pin
shabonaa6-Oct-06 10:27
shabonaa6-Oct-06 10:27 
AnswerRe: Computer Generated Random Numbers Pin
led mike6-Oct-06 11:55
led mike6-Oct-06 11:55 
AnswerRe: Computer Generated Random Numbers Pin
Guffa6-Oct-06 12:41
Guffa6-Oct-06 12:41 
QuestionRe: Computer Generated Random Numbers Pin
shabonaa6-Oct-06 13:20
shabonaa6-Oct-06 13:20 
AnswerRe: Computer Generated Random Numbers Pin
Guffa6-Oct-06 13:27
Guffa6-Oct-06 13:27 
GeneralRe: Computer Generated Random Numbers Pin
shabonaa6-Oct-06 13:46
shabonaa6-Oct-06 13:46 
AnswerRe: Computer Generated Random Numbers Pin
Guffa6-Oct-06 15:26
Guffa6-Oct-06 15:26 
GeneralRe: Computer Generated Random Numbers Pin
shabonaa6-Oct-06 15:52
shabonaa6-Oct-06 15:52 
AnswerRe: Computer Generated Random Numbers Pin
Amar Chaudhary6-Oct-06 19:56
Amar Chaudhary6-Oct-06 19:56 
QuestionValueMember in combobox Pin
microuser_20006-Oct-06 10:23
microuser_20006-Oct-06 10:23 
QuestionHow to upgrade mdb database Pin
nhuythanh6-Oct-06 10:14
nhuythanh6-Oct-06 10:14 
AnswerRe: How to upgrade mdb database Pin
Amar Chaudhary6-Oct-06 11:51
Amar Chaudhary6-Oct-06 11:51 
QuestionHow to print Datagrid in C# ? Pin
hdv2126-Oct-06 10:05
hdv2126-Oct-06 10:05 
Question[Message Deleted] Pin
Wolf926-Oct-06 8:42
Wolf926-Oct-06 8:42 
AnswerRe: Christmas gift ideas? Pin
led mike6-Oct-06 8:51
led mike6-Oct-06 8:51 
AnswerRe: Christmas gift ideas? Pin
Amar Chaudhary6-Oct-06 9:21
Amar Chaudhary6-Oct-06 9:21 

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.