Logo

Programming-Idioms

History of Idiom 109 > diff from v9 to v10

Edit summary for version 10 by programming-idioms.org:
[Ada] Fixed bit to bytes conversion. Improved comments.

Version 9

2016-02-18, 16:58:03

Version 10

2016-11-09, 12:41:50

Idiom #109 Number of bytes of a type

Set n to the number of bytes of a variable of type T.
This makes different sense (if any), depending on the language.

Idiom #109 Number of bytes of a type

Set n to the number of bytes of a variable of type T.
This makes different sense (if any), depending on the language.

Code
N : Integer := T'Size / 8;
Code
N : Integer := (T'Size + 7) / 8;
Comments bubble
T'Size returns size of T in bits, divide by 8 to convert to bytes
Comments bubble
T'Size returns size of T in bits. It is the minimum number of bits required to store an object of that type.
Divide by 8 to convert to bytes