TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Carl
NA
11
0
How do I create a parity bool from a range of bools?
Jun 12 2007 5:16 PM
In c you have the possibility to add up your bools and then mod the result with 2, but in the stricter typed language c# you have to add a lot of typecasts to do the same. I hope there is some more esthetical way of doing this?
c sourcecode:
int array_out[12];
...
array_out[11] = (array_out[0] + array_out[1] + array_out[2] + array_out[3] + array_out[4] + array_out[5] + array_out[6] + array_out[7] + array_out[8] + array_out[9] + array_out[10]) % 2;
c# equivalent:
bool[] array_out= new bool[12];
...
array_out[11] = (((array_out[0] ? 1 : 0) + (array_out[1] ? 1 : 0) + (array_out[2] ? 1 : 0) + (array_out[3] ? 1 : 0) + (array_out[4] ? 1 : 0) + (array_out[5] ? 1 : 0) + (array_out[6] ? 1 : 0) + (array_out[7] ? 1 : 0) + (array_out[8] ? 1 : 0) + (array_out[9] ? 1 : 0) + (array_out[10] ? 1 : 0)) % 2) == 1;
Reply
Answers (
1
)
Regex to Validate IP Addresses
NP11 B MyB = new D()