Recent

Author Topic: testing bitwise operateur with if statement  (Read 494 times)

andromeda

  • New Member
  • *
  • Posts: 12
testing bitwise operateur with if statement
« on: November 24, 2020, 01:41:16 am »
Hi,

i have an error with the code below:(I use lazarus last version on windows 10 x64)
Code: Pascal  [Select][+][-]
  1. procedure textcolor(color : byte);
  2. begin
  3.   _putch(CSI);
  4.   _putch(BRACKET);
  5.  
  6.   if (color and $8) then  <= error: incompatibles types: got "Byte" expected "Boolean"
  7.           _putch($31)
  8.   else _putch($32);
  9.   _putch($6D);
  10.  
  11.   _putch(CSI);
  12.   _putch(BRACKET);
  13.   _putch($33);
  14.   _putch(((color and $7) mod 10)+'0');
  15.   _putch($6D);
  16. end;      
  17.  

Equivalent to C code that work is:
Code: Pascal  [Select][+][-]
  1. void textcolor(int color)
  2. {
  3.   _putch('\033');
  4.   _putch('[');
  5.   if (color & 0x8)
  6.           _putch('1');
  7.   else _putch('2');
  8.   _putch('m');
  9.  
  10.   _putch('\033');
  11.   _putch('[');
  12.   _putch('3');
  13.   _putch(((color&0x7)%10)+'0');
  14.   _putch('m');
  15. }
  16.  
  17.  

for information, _putch is defined as below:
i use lazSerial for sending VT100 on serial.

Code: Pascal  [Select][+][-]
  1. procedure _putch(data : byte);
  2. begin
  3.      ser.SendByte(data);
  4. end;  
  5.  

i don't see the error, the C code wotk fine

thanks for your help

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: testing bitwise operateur with if statement
« Reply #1 on: November 24, 2020, 01:57:36 am »
Try
Code: Pascal  [Select][+][-]
  1. if (color and $8)>0 then
Pascal accepts only boolean expressions, it is difference to C.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: testing bitwise operateur with if statement
« Reply #2 on: November 24, 2020, 02:00:59 am »
Sorry, Pascal or at least fpc does not allow the luxury of short term Booleans..

To bad too...
The only true wisdom is knowing you know nothing

andromeda

  • New Member
  • *
  • Posts: 12
Re: testing bitwise operateur with if statement
« Reply #3 on: November 24, 2020, 02:24:04 am »
thank you for your response, it work now.

 

TinyPortal © 2005-2018