Answer the question
In order to leave comments, you need to log in
What is the binary data type in C#?
Good afternoon. You need to implement bitwise or and chose a variable of type bool to work:
bool[] st = new bool[] { false, true, true, true, false, true, false, false, true, true, true, true};
Answer the question
In order to leave comments, you need to log in
Well, whatever, although they usually do something like this
unsigned int myAdd(unsigned int a, unsigned int b)
{
unsigned int carry = a & b;
unsigned int result = a ^ b;
while(carry != 0)
{
unsigned int shiftedcarry = carry << 1;
carry = result & shiftedcarry;
result ^= shiftedcarry;
}
return result;
}
public struct MyBool
{
private byte _val;
public byte Value
{
get { return _val; }
set { _val = (byte)(value == 0 ? 0 : 1); }
}
public MyBool(int a)
{
_val = (byte)(a == 0 ? 0 : 1);
}
public override string ToString()
{
return _val == 0 ? "0" : "1";
}
public override int GetHashCode()
{
return _val;
}
public override bool Equals(object obj)
{
return _val == ((MyBool)obj).Value;
}
public static implicit operator MyBool(int a)
{
return new MyBool(a);
}
public static implicit operator int(MyBool a)
{
return a._val;
}
}
MyBool[] arr1 = {1, 0, 1, 1, 0, 0, 0, 1};
MyBool[] arr2 = {1, 0, 2, 3, 0, 0, 0, -5};
// автоматически преобразуется в {1, 0, 1, 1, 0, 0, 0, 1}
// во всех си-подобных языках не-ноль - это истина
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question