Click here to Skip to main content
15,886,518 members
Home / Discussions / C#
   

C#

 
GeneralRe: Looking for help deciphering this code class Pin
turbosupramk314-Jan-12 3:41
turbosupramk314-Jan-12 3:41 
GeneralRe: Looking for help deciphering this code class Pin
OriginalGriff14-Jan-12 3:53
mveOriginalGriff14-Jan-12 3:53 
GeneralRe: Looking for help deciphering this code class Pin
harold aptroot14-Jan-12 4:47
harold aptroot14-Jan-12 4:47 
GeneralRe: Looking for help deciphering this code class Pin
OriginalGriff14-Jan-12 5:03
mveOriginalGriff14-Jan-12 5:03 
GeneralRe: Looking for help deciphering this code class Pin
harold aptroot14-Jan-12 5:22
harold aptroot14-Jan-12 5:22 
GeneralRe: Looking for help deciphering this code class Pin
OriginalGriff14-Jan-12 5:31
mveOriginalGriff14-Jan-12 5:31 
GeneralRe: Looking for help deciphering this code class Pin
turbosupramk314-Jan-12 8:18
turbosupramk314-Jan-12 8:18 
GeneralRe: Looking for help deciphering this code class Pin
harold aptroot14-Jan-12 9:34
harold aptroot14-Jan-12 9:34 
The long-hand version is only meant to show what ?: does, it is not the same thing. The problem here is that if/else is a statement (so it has no value, only a side effect) and a?b:c is an expression (it computes a value).
On top of that, the || operator is a short circuiting operator that obviously (once you know what it does) can not work on bytes.
Furthermore, in C# arithmetic operators on bytes produce ints as result, so even if you fixed the other errors the compiler would complain about the type.

But that's all easy to solve, for example:
- by writing (byte)(IterateLFSR() ? 0xFF : 0xFE)
- by writing
C#
byte x;
if (IterateLFSR())
    x = 0xFF;
else
    x = 0xFE;
(and then using x, of course)
- or (byte)(IterateLFSR() | 0xFE) if you change IterateLFSR to this:
C#
private int IterateLFSR()
{
    _LFSR = unchecked((byte)((_LFSR << 1) | (_LFSR >> 7 ^ _LFSR >> 5 ^ _LFSR >> 4 ^ _LFSR >> 1) & 1));
    return _LFSR >> 1; // the previous bit is still available, it just moved one place
}

I moved some stuff around there, but the result is the same (as a bit in an int instead of a bool that has to be converted back to that bit). The other bits in the result should be treated as garbage. Or-ing it with something that has 1 in all the high bits throws them out which is why it isn't a problem in IterateLFSR() | 0xFE.
GeneralRe: Looking for help deciphering this code class Pin
turbosupramk315-Jan-12 5:23
turbosupramk315-Jan-12 5:23 
AnswerRe: Looking for help deciphering this code class Pin
BobJanova15-Jan-12 23:11
BobJanova15-Jan-12 23:11 
QuestionOnline users Pin
RichardKly13-Jan-12 6:37
RichardKly13-Jan-12 6:37 
AnswerRe: Online users Pin
PIEBALDconsult13-Jan-12 6:47
mvePIEBALDconsult13-Jan-12 6:47 
AnswerRe: Online users Pin
Qendro13-Jan-12 6:54
Qendro13-Jan-12 6:54 
Questionhwo to sort observabale collection? Pin
SRKSHOME13-Jan-12 3:08
SRKSHOME13-Jan-12 3:08 
AnswerRe: hwo to sort observabale collection? PinPopular
Abhinav S13-Jan-12 3:19
Abhinav S13-Jan-12 3:19 
AnswerRe: hwo to sort observabale collection? Pin
DaveyM6913-Jan-12 4:53
professionalDaveyM6913-Jan-12 4:53 
Questionhow do u execute this Pin
kkcarthieckk13-Jan-12 2:24
kkcarthieckk13-Jan-12 2:24 
AnswerRe: how do u execute this Pin
Richard MacCutchan13-Jan-12 3:06
mveRichard MacCutchan13-Jan-12 3:06 
Questionhow do u execute this Pin
kkcarthieckk13-Jan-12 2:23
kkcarthieckk13-Jan-12 2:23 
Questionset to 640x480 wmv files Pin
is90057james12-Jan-12 19:28
is90057james12-Jan-12 19:28 
AnswerRe: set to 640x480 wmv files Pin
Abhinav S12-Jan-12 20:57
Abhinav S12-Jan-12 20:57 
Generalhi frnds Pin
mbjino12-Jan-12 18:31
mbjino12-Jan-12 18:31 
GeneralRe: hi frnds Pin
Calla12-Jan-12 20:50
Calla12-Jan-12 20:50 
GeneralRe: hi frnds Pin
V.12-Jan-12 20:53
professionalV.12-Jan-12 20:53 
GeneralRe: hi frnds Pin
Abhinav S12-Jan-12 20:55
Abhinav S12-Jan-12 20:55 

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.