ARM Technical Support Knowledge Articles

IMPLEMENTATION OF 'BIT' TYPE CASTS

Applies to: General Topics

Answer


Information in this article applies to:


QUESTION

The Keil C Compiler support the data type bit. However, the compiler manual lacks information on the way type casts are implemented with this data type.

ANSWER

You are correct, the Manual does not contain this information.

When a integer or float type is casted to a bit, the value is compared with 0. If the value is not '0', the bit is set to '1'. The operation is identical with the behavior in compare statements.

Example:

  unsigned char uc;
  bit           b;

  b = uc;  /* is identical to: */  if (uc) b = 1;  else b = 0;

A bit cast to a scalar type sets the value to 0 when the bit is clear; 1 when the bit is set.

Article last edited on: 2004-05-03 20:14:34

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential