473,854 Members | 1,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

convert type 'byte' to 'bool'

Hi,

I try to print out truth-tables for an &&-operation using the following
code, unfortunatly I get compiler errors :

for ( byte i1=0; i1<=1; i1++)
{
for ( byte i2=0; i2<=1; i2++)
{
bool a = (bool)i1; // ERROR : convert type 'byte' to 'bool'
bool b = (bool)i2; // ERROR : convert type 'byte' to 'bool'
bool result = a && b;
}
}

how do I solve this ?
thnx
Chris
Nov 16 '05 #1
14 29562
bool a = Convert.ToBoole an(i1);

Willy.

"Chris" <ch********@pan dora.be> wrote in message
news:tv******** *************** @phobos.telenet-ops.be...
Hi,

I try to print out truth-tables for an &&-operation using the following
code, unfortunatly I get compiler errors :

for ( byte i1=0; i1<=1; i1++)
{
for ( byte i2=0; i2<=1; i2++)
{
bool a = (bool)i1; // ERROR : convert type 'byte' to 'bool'
bool b = (bool)i2; // ERROR : convert type 'byte' to 'bool'
bool result = a && b;
}
}

how do I solve this ?
thnx
Chris

Nov 16 '05 #2
Why not just do "bool result = i1 && i2".

"Chris" <ch********@pan dora.be> wrote in message
news:tv******** *************** @phobos.telenet-ops.be...
Hi,

I try to print out truth-tables for an &&-operation using the following
code, unfortunatly I get compiler errors :

for ( byte i1=0; i1<=1; i1++)
{
for ( byte i2=0; i2<=1; i2++)
{
bool a = (bool)i1; // ERROR : convert type 'byte' to 'bool'
bool b = (bool)i2; // ERROR : convert type 'byte' to 'bool'
bool result = a && b;
}
}

how do I solve this ?
thnx
Chris

Nov 16 '05 #3
use Convert.ToBoole an instead of using (bool) i1

Convert.ToBoole an(i1);

It will work this way.

Regards,

Tarakeshwar

"Chris" <ch********@pan dora.be> wrote in message
news:tv******** *************** @phobos.telenet-ops.be...
Hi,

I try to print out truth-tables for an &&-operation using the following
code, unfortunatly I get compiler errors :

for ( byte i1=0; i1<=1; i1++)
{
for ( byte i2=0; i2<=1; i2++)
{
bool a = (bool)i1; // ERROR : convert type 'byte' to 'bool'
bool b = (bool)i2; // ERROR : convert type 'byte' to 'bool'
bool result = a && b;
}
}

how do I solve this ?
thnx
Chris

Nov 16 '05 #4
Hi,

Assuming that you consider a value different to 0 true ( the default ) ,
this will do:

bool b = byte >0;
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Chris" <ch********@pan dora.be> wrote in message
news:tv******** *************** @phobos.telenet-ops.be...
Hi,

I try to print out truth-tables for an &&-operation using the following
code, unfortunatly I get compiler errors :

for ( byte i1=0; i1<=1; i1++)
{
for ( byte i2=0; i2<=1; i2++)
{
bool a = (bool)i1; // ERROR : convert type 'byte' to 'bool'
bool b = (bool)i2; // ERROR : convert type 'byte' to 'bool'
bool result = a && b;
}
}

how do I solve this ?
thnx
Chris

Nov 16 '05 #5
Peter Rilling <pe***@nospam.r illing.net> wrote:
Why not just do "bool result = i1 && i2".


Because there's no operator && which has byte on each side of it.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Doh!

Stupid me. :)

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Peter Rilling <pe***@nospam.r illing.net> wrote:
Why not just do "bool result = i1 && i2".


Because there's no operator && which has byte on each side of it.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #7
I also enjoy doing something like:

bool a = bool.Parse(i2.T oString());
"Chris" <ch********@pan dora.be> wrote in message
news:tv******** *************** @phobos.telenet-ops.be...
Hi,

I try to print out truth-tables for an &&-operation using the following
code, unfortunatly I get compiler errors :

for ( byte i1=0; i1<=1; i1++)
{
for ( byte i2=0; i2<=1; i2++)
{
bool a = (bool)i1; // ERROR : convert type 'byte' to 'bool'
bool b = (bool)i2; // ERROR : convert type 'byte' to 'bool'
bool result = a && b;
}
}

how do I solve this ?
thnx
Chris

Nov 16 '05 #8
Drebin <th*******@hotm ail.com> wrote:
I also enjoy doing something like:

bool a = bool.Parse(i2.T oString());


You may enjoy it, but it's just an expensive way of doing

bool a = false;

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #9
Jon Skeet [C# MVP] <sk***@pobox.co m> wrote:
Drebin <th*******@hotm ail.com> wrote:
I also enjoy doing something like:

bool a = bool.Parse(i2.T oString());


You may enjoy it, but it's just an expensive way of doing

bool a = false;


Apologies - it's actually an expensive way of throwing a new
FormatException . Still doesn't do anything useful though ;)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
1094
by: djozy | last post by:
Please, how can I convert selected item from dropdown list to integer? Thank you
2
29523
by: jiangyh | last post by:
hi there : I have a question about how to convert Type to DbType? thanks a lot. jiangyh
2
1394
by: Chris Wood | last post by:
In C#, I am calling a method implemented in Managed C++ that returns an array of booleans. This method in turn calls unto unmanaged C++ code that returns an unsigned byte array, which is implicitly casted to a bool __gc . However, in my client C# app, when I examine this array in the locals window, it shows "bool" as the type of the array and "byte" as the type of each element. If I try this in Whidbey beta, it shows "bool {byte}" and...
2
9924
by: Anthony Borla | last post by:
Greetings, I hope everyone is enjoying the Holiday Season :) ! I'm attempting to implement a function template modelled somewhat on the STL's, 'generate' and 'generate_n' algorithms. Now, 'generate_while', requires the use of temporary storage : template <class OutputIter_, class Generator_, class Predicate_> OutputIter_ generate_while(OutputIter_ first_,
5
3796
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public List<RoleData> GetRoles() { return GetRoles(null, false); }
4
41651
by: msosno01 | last post by:
I have Java client that connects to C++ server. The client sends integer in binary using DataOutputStream write function. I am reading these data into buffer. I have to convert this buffer back into integer, but I am not sure how to do it. This is my code: int32_t var1; uint8_t buf;
13
9701
by: Bob | last post by:
Hi, I have a newbie question. What is the smallest type object size? I am doing some calculation with individual bits and want to minimize memory usage. I though bool might do it but it seems like each bool is a byte, instead of a bit. Is bool the smallest possible type? Thanks, Bob
3
3860
by: efdeugenio | last post by:
Hi, I will really appreciate if someone cans help me with this: I have a managed c++ class that I am calling from C#. The declaration of a function in this class is: bool CanAddTemplate(unsigned char* template, HRESULT rc, bool bInteractive) When calling this function from c# I have: byte template = new Byte; bresult = CIdentificationSet.CanAddTemplate(template, rc, true);
0
10797
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
9901
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11024
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10749
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9512
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5740
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4152
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.