-4

I am updating an existing library in Java I have to connect to MySQL 8 but the source code documentation has a #DEFINE I don't understand. I'm looking specifically at the client capability flags at https://dev.mysql.com/doc/dev/mysql-server/latest/group__group__cs__capabilities__flags.html.

Some of the capability flags show the decimal value so I can convert them to unix for easier bitmasking but there's some flags like CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS which has the value of (1UL << 22). I have no idea what (1UL << 22) means to be able convert that to something I can use in java.

Boardy
  • 35,417
  • 104
  • 256
  • 447
  • why java tag if you don't understand C document? – rkosegi Jan 25 '20 at 21:34
  • 2
    It should be 1 shifted left 22 times, that is 2^22, that is 4*1024*1024. – Roberto Caboni Jan 25 '20 at 21:35
  • Because I'm working on Java and I've done plenty of stuff but never seen that (They don't have java documentation) – Boardy Jan 25 '20 at 21:35
  • Surely you should read the docs for the language it's written in (C++)? UL is unsigned long, for example. – jonrsharpe Jan 25 '20 at 21:36
  • In this specific case it is just a flag which value is, in a specific register, the bit 22 of the register (bits count starts with 0) – Roberto Caboni Jan 25 '20 at 21:38
  • 1
    @RobertoCaboni Thanks for the help, that's done what I was expecting. Didn't realise it was as simple as a bitshift, it was the UL that was throwing me :) – Boardy Jan 25 '20 at 21:41
  • I expected UL might have stood for Unsigned Long I've done C/C++ but I'd never seen a #define like that so hadn't realised it was as simple as a bitwise operation – Boardy Jan 25 '20 at 21:42

1 Answers1

0

Generally speaking, (1UL << 22) means 1 shifted left 22 times within an Unsigned Long.

That is 2^22, that is 4*1024*1024.

In your case CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS is just a flag that is enable, in its specific unsigned long register, if bit 22 of the register is 1 (bits count starts with 0).

Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39