Next: , Previous: , Up: stdlib bytevector   [Index]


5.2.6 Operations on 32–bit integers

Procedure: bytevector-u32-ref bytevector k endianness
Procedure: bytevector-s32-ref bytevector k endianness
Procedure: bytevector-u32-native-ref bytevector k
Procedure: bytevector-s32-native-ref bytevector k
Procedure: bytevector-u32-set! bytevector k n endianness
Procedure: bytevector-s32-set! bytevector k n endianness
Procedure: bytevector-u32-native-set! bytevector k n
Procedure: bytevector-s32-native-set! bytevector k n

k, …, k+3 must be valid indices of bytevector.

For bytevector-u32-set! and bytevector-u32-native-set!, n must be an exact integer object in the interval 0 <= n <= 2^{32}-1.

For bytevector-s32-set! and bytevector-s32-native-set!, n must be an exact integer object in the interval -2^{31} <= n <= 2^{32}-1.

These retrieve and set four–byte representations of numbers at indices k, …, k+3, according to the endianness specified by endianness. The procedures with u32 in their names deal with the unsigned representation; those with s32 with the two’s–complement representation.

The procedures with native in their names employ the native endianness, and work only at aligned indices: k must be a multiple of 4.

The ...-set! procedures return unspecified values.

(define b
  (u8-list->bytevector
    '(255 255 255 255 255 255 255 255
      255 255 255 255 255 255 255 253)))

(bytevector-u32-ref b 12 (endianness little))   ⇒ 4261412863
(bytevector-s32-ref b 12 (endianness little))   ⇒ -33554433
(bytevector-u32-ref b 12 (endianness big))      ⇒ 4294967293
(bytevector-s32-ref b 12 (endianness big))      ⇒ -3