"Invalid operands 'int' and 'int' in operator '<<'."

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By HaleyHalcyon

I have this code that converts four 8-bit integers into one 32-bit integer with big-endian encoding:

var score_to_beat = data[1] << 24 + data[2] << 16 + data[3] << 8 + data[4]

However, when I try to do that with all the integers set to 255, Godot gave me this error:

Invalid operands 'int' and 'int' in operator '<<'.

Isn’t the bit shift operator supposed to take two integers? What’s the real problem here?

:bust_in_silhouette: Reply From: mrimvo

Putting brackets solves it for me like (data[1] << 24) + .... Probably + got a higher priority than <<?

Apparently so according to this.

Edit: Fixed link lol

exuin | 2021-04-23 21:07