+1 vote

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?

Godot version v3.2.3.stable.official
in Engine by (86 points)

1 Answer

0 votes

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

by (58 points)

Apparently so according to this.

Edit: Fixed link lol

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.