Home > Software design >  Is there a way to get a Bit field in SQL (non transact)
Is there a way to get a Bit field in SQL (non transact)

Time:04-07

Let's say the field comes with a number like 134479872, I'd like it to revert back to 0xffffffff and extract each pair like Oxff00000, 0x00ff0000, 0x0000ff00 and 0x000000ff in a separate field. The bits are supposed to tell me info about a left, right, top and bottom edge: First two bits are for the left edge, two next ones for the right and so on.

Now I tried SELECT CAST(myfield as Binary(8)) to get the 0xffffffff format but it does not accept it. From there I could work with Mid() to get the two fields I need, that last part I am ok with it.

Note that my SQL is dealt with Access 2010, and it does not accept Transact-SQL functions.

Thank you in advance

CodePudding user response:

You could use the Hex$() function.

? Hex$(134479872)
8040000

To pad it to 8 characters:

? Right("00000000" & Hex$(134479872), 8)
08040000

But if you utilize the full 64 bits, you will run into problems - VBA Longints are signed.

? &H7FFFFFFF
 2147483647 

? Hex$(2147483648)
<Overflow error>
  • Related