Click here to Skip to main content
15,887,962 members
Home / Discussions / C#
   

C#

 
GeneralRe: Invalid Argument in For Loop Pin
computerpublic2-Mar-14 8:33
computerpublic2-Mar-14 8:33 
QuestionRe: Invalid Argument in For Loop Pin
Eddy Vluggen2-Mar-14 9:04
professionalEddy Vluggen2-Mar-14 9:04 
AnswerMessage Closed Pin
2-Mar-14 9:17
computerpublic2-Mar-14 9:17 
GeneralRe: Invalid Argument in For Loop Pin
Richard MacCutchan2-Mar-14 22:43
mveRichard MacCutchan2-Mar-14 22:43 
AnswerRe: Invalid Argument in For Loop Pin
noone24072-Mar-14 17:46
noone24072-Mar-14 17:46 
GeneralRe: Invalid Argument in For Loop Pin
computerpublic2-Mar-14 18:00
computerpublic2-Mar-14 18:00 
GeneralRe: Invalid Argument in For Loop Pin
noone24072-Mar-14 18:32
noone24072-Mar-14 18:32 
AnswerRe: Invalid Argument in For Loop Pin
OriginalGriff2-Mar-14 22:49
mveOriginalGriff2-Mar-14 22:49 
There are two problems here: firstly that an array index needs to be an integer - and a uint needs an explicit cast to int - you can't use an implicit cast because it could "throw away" data in the form of positive values with the top bit set. Easiest solution: use int value in your for loop.

The second problem is that the BitArray indexer does not return an int value: it returns a bool. So if you correct the first error, the compiler will complain that it cannot compare an int with a bool!

Those are easily fixed to let your program compile:
C#
for (int counter = 0; counter < Totbyte; counter++)
    {
    dataB[0] = data[counter];
    for (int count = 0; count < bits.Length; count++)
        {
        if (!bits[count])
            Console.Write(bits[count] ? "1" : "0");
        }
    }
But... It's not going to work.
You don't change the value in Bits at all inside your outer loop - so each byte "value" is going to print as the same sequence of bits.

Personally, I wouldn't use a BitArray - it's an unnecessary complication here - just use the C# standard bit manipulation operators:
C#
for (int counter = 0; counter < Totbyte; counter++)
    {
    int b = (int) data[counter];
    for (int count = 0; count < 8; count++)
        {
            Console.Write(b & 1);
            b = b >> 1;
        }
    }

Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

GeneralRe: Invalid Argument in For Loop Pin
computerpublic3-Mar-14 3:52
computerpublic3-Mar-14 3:52 
GeneralRe: Invalid Argument in For Loop Pin
OriginalGriff3-Mar-14 4:30
mveOriginalGriff3-Mar-14 4:30 
AnswerRe: Invalid Argument in For Loop Pin
Richard MacCutchan2-Mar-14 22:54
mveRichard MacCutchan2-Mar-14 22:54 
GeneralRe: Invalid Argument in For Loop Pin
computerpublic3-Mar-14 3:53
computerpublic3-Mar-14 3:53 
GeneralRe: Invalid Argument in For Loop Pin
Richard MacCutchan3-Mar-14 4:11
mveRichard MacCutchan3-Mar-14 4:11 
GeneralRe: Invalid Argument in For Loop Pin
computerpublic3-Mar-14 4:16
computerpublic3-Mar-14 4:16 
GeneralRe: Invalid Argument in For Loop Pin
Richard MacCutchan3-Mar-14 4:22
mveRichard MacCutchan3-Mar-14 4:22 
GeneralRe: Invalid Argument in For Loop Pin
computerpublic3-Mar-14 7:39
computerpublic3-Mar-14 7:39 
GeneralRe: Invalid Argument in For Loop Pin
Richard MacCutchan3-Mar-14 21:59
mveRichard MacCutchan3-Mar-14 21:59 
GeneralRe: Invalid Argument in For Loop Pin
computerpublic4-Mar-14 3:55
computerpublic4-Mar-14 3:55 
GeneralRe: Invalid Argument in For Loop Pin
Richard MacCutchan4-Mar-14 5:25
mveRichard MacCutchan4-Mar-14 5:25 
Generalapplication icons??? Pin
Member 106142622-Mar-14 1:56
Member 106142622-Mar-14 1:56 
GeneralRe: application icons??? Pin
Pete O'Hanlon2-Mar-14 2:08
mvePete O'Hanlon2-Mar-14 2:08 
JokeRe: application icons??? Pin
dan!sh 2-Mar-14 23:45
professional dan!sh 2-Mar-14 23:45 
GeneralRe: application icons??? Pin
Ravi Bhavnani2-Mar-14 5:57
professionalRavi Bhavnani2-Mar-14 5:57 
GeneralRe: application icons??? Pin
Bernhard Hiller2-Mar-14 23:52
Bernhard Hiller2-Mar-14 23:52 
QuestionHow i can redirect URLs entered in the browser with C#? Pin
Amin Soltani1-Mar-14 22:56
Amin Soltani1-Mar-14 22:56 

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.