link
SDK
One stop solution for all Vulkan samples
Rust)
In Vulkan code, you will often see something like:
16 << 10This is a left bit shift. Let’s break it down.
1. << means “shift bits to the left”
The expression:
16 << 10means:
Take the binary representation of
16and move its bits 10 positions to the left.
16 in binary is:
16 = 0000000000010000Shift left by 10:
0000000000010000
↓↓↓↓↓↓↓↓↓↓
0100000000000000The result is:
16 << 10 = 16384Mathematically, for positive integers:
x << n = x × 2ⁿTherefore:
16 << 10
= 16 × 2¹⁰
= 16 × 1024
= 163842. Why does Vulkan code use this?
A common reason is to express powers-of-two sizes or bit fields clearly.
For example:
#define MAX_SIZE (16 << 10)means:
16 KiBbecause:
16 × 1024 = 16384 bytesSo:
16 << 10is another way of writing:
16384or:
16 * 1024But the bit-shift form emphasizes that the value is based on binary powers of two.
3. Why 10?
Because:
2¹⁰ = 1024So:
x << 10is equivalent to:
x × 1024For example:
1 << 10 = 1024
2 << 10 = 2048
4 << 10 = 4096
8 << 10 = 8192
16 << 10 = 16384This is particularly natural for memory-related Vulkan programming because GPUs and Vulkan resources frequently use power-of-two / binary-aligned sizes.
4. Compare with 16 << 20
You will also frequently see:
16 << 20Since:
2²⁰ = 1,048,576we get:
16 << 20
= 16 × 1,048,576
= 16,777,216That’s 16 MiB.
So:
16 << 10 → 16 KiB
16 << 20 → 16 MiBassuming the context is measuring bytes.
5. A useful way to read it
When you see:
16 << 10you can mentally read it as:
“16 times 2 to the 10th.”
Similarly:
1 << 20means:
“2 to the 20th”
and:
64 << 10means:
“64 KiB.”
One important distinction
Don’t confuse:
16 << 10with:
16 >> 10<< moves bits left:
16 << 10 = 16384while >> moves bits right:
16 >> 10 = 0for ordinary integer arithmetic, because the 16’s set bit gets shifted away.
In Vulkan code, << is often used for bit masks, flags, alignment values, and binary-sized quantities, so understanding it is very useful when reading Vulkan headers and examples.