Index: uspace/drv/bus/usb/usbmast/inquiry.c
===================================================================
--- uspace/drv/bus/usb/usbmast/inquiry.c	(revision dcb74c0af02cb41ce55ef7d1413cdf60fdf07961)
+++ uspace/drv/bus/usb/usbmast/inquiry.c	(revision 64e6945d93bd4d55558a3f118f2ba2c451a627c3)
@@ -34,4 +34,5 @@
  * Main routines of USB mass storage driver.
  */
+#include <bitops.h>
 #include <usb/dev/driver.h>
 #include <usb/debug.h>
@@ -45,10 +46,4 @@
 #include "cmds.h"
 #include "mast.h"
-
-#define BITS_GET_MASK(type, bitcount) (((type)(1 << (bitcount)))-1)
-#define BITS_GET_MID_MASK(type, bitcount, offset) \
-	((type)( BITS_GET_MASK(type, (bitcount) + (offset)) - BITS_GET_MASK(type, bitcount) ))
-#define BITS_GET(type, number, hi_bit, lo_bit) \
-	((type)( (number) & (BITS_GET_MID_MASK(type, (hi_bit)-(lo_bit)+1, lo_bit)) ) >> (lo_bit))
 
 /** Get string representation for SCSI peripheral device type.
@@ -107,9 +102,9 @@
 	bzero(inquiry_result, sizeof(*inquiry_result));
 
-	inquiry_result->device_type = BITS_GET(uint8_t, inq_data.pqual_devtype,
-	    SCSI_PQDT_DEV_TYPE_h, SCSI_PQDT_DEV_TYPE_l);
+	inquiry_result->device_type = BIT_RANGE_EXTRACT(uint8_t,
+	    inq_data.pqual_devtype, SCSI_PQDT_DEV_TYPE_h, SCSI_PQDT_DEV_TYPE_l);
 
-	inquiry_result->removable = BITS_GET(uint8_t, inq_data.rmb,
-	    SCSI_RMB_RMB, SCSI_RMB_RMB);
+	inquiry_result->removable = BIT_RANGE_EXTRACT(uint8_t,
+	    inq_data.rmb, SCSI_RMB_RMB, SCSI_RMB_RMB);
 
 	spascii_to_str(inquiry_result->vendor, SCSI_INQ_VENDOR_STR_BUFSIZE,
Index: uspace/lib/c/include/bitops.h
===================================================================
--- uspace/lib/c/include/bitops.h	(revision dcb74c0af02cb41ce55ef7d1413cdf60fdf07961)
+++ uspace/lib/c/include/bitops.h	(revision 64e6945d93bd4d55558a3f118f2ba2c451a627c3)
@@ -38,4 +38,19 @@
 #include <sys/types.h>
 
+/** Mask with bit @a n set. */
+#define BIT_V(type, n) \
+    ((type)1 << ((n) - 1))
+
+/** Mask with rightmost @a n bits set. */
+#define BIT_RRANGE(type, n) \
+    (BIT_V(type, (n) + 1) - 1)
+
+/** Mask with bits @a hi .. @a lo set. @a hi >= @a lo. */
+#define BIT_RANGE(type, hi, lo) \
+    (BIT_RRANGE(type, (hi) - (lo) + 1) << (lo))
+
+/** Extract range of bits @a hi .. @a lo from @a value. */
+#define BIT_RANGE_EXTRACT(type, hi, lo, value) \
+    (((value) >> (lo)) & BIT_RRANGE(type, (hi) - (lo) + 1))
 
 /** Return position of first non-zero bit from left (i.e. [log_2(arg)]).
