Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › crypto › ff › Uint › fromBytes Public Function fromBytes Doc Source Public Function std.crypto.ff.Uint.fromBytes
pub fn fromBytes (bytes : []const u8 , comptime endian : Endian ) OverflowError !Self Params bytes : []const u8 endian : Endian Errors File crypto/ff.zig: 185
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223 pub fn fromBytes (bytes : []const u8 , comptime endian : Endian ) OverflowError !Self {
if (bytes .len == 0 ) return Self .zero ;
var shift : usize = 0 ;
var out = Self .zero ;
var out_i : usize = 0 ;
var i : usize = switch (endian ) {
.big => bytes .len - 1 ,
.little => 0 ,
};
while (true ) {
const bi = bytes [i ];
out .limbs ()[out_i ] |= math .shl (Limb , bi , shift );
shift += 8 ;
if (shift >= t_bits ) {
shift -= t_bits ;
out .limbs ()[out_i ] = @as (TLimb , @truncate (out .limbs ()[out_i ]));
const overflow = math .shr (Limb , bi , 8 - shift );
out_i += 1 ;
if (out_i >= out .limbs_len ) {
if (overflow != 0 or i != 0 ) {
return error .Overflow ;
}
break ;
}
out .limbs ()[out_i ] = overflow ;
}
switch (endian ) {
.big => {
if (i == 0 ) break ;
i -= 1 ;
},
.little => {
i += 1 ;
if (i == bytes .len ) break ;
},
}
}
return out ;
}
Creates a new big integer from a byte array.