user734781
user734781

Reputation: 273

What's the Delphi equivalent to C++'s "unsigned char"?

How can I convert the following C++ code to Delphi? In particular, what is isenable? I am trying to find out if this value is being added.

unsigned char isenable = 0;
if (m_Isbuzzer)
{
    isenable = isenable | 0x01;
}
if (m_Isled)
{
    isenable = isenable | 0x02;
}

Upvotes: 1

Views: 2787

Answers (1)

David Heffernan
David Heffernan

Reputation: 613222

On Windows, char is an 8 bit type, and unsigned means, well, unsigned. Typically, unsigned char is used for binary byte oriented data. So map unsigned char to Byte. The excellent article that Rudy Velthuis wrote, Pitfalls of converting, contains this information.

The | operator is bitwise OR. The C++ operators are listed and well documented here: http://en.cppreference.com/w/cpp/language/expressions#Operators In Delphi bitwise OR is the or operator.

So the code would be:

var
  isenable: Byte;
....
isenable := 0;
if IsBuzzer then
  isenable := isenable or $01;
if IsLED then
  isenable := isenable or $02;

Upvotes: 4

Related Questions