Skip to content

Replace 32 with BitsSize #106

@konard

Description

@konard

public static T PartialWrite(T target, T source, int shift, int limit)
{
if (shift < 0)
{
shift = 32 + shift;
}
if (limit < 0)
{
limit = 32 + limit;
}
var sourceMask = ~(T.MaxValue << limit) & T.MaxValue;
var targetMask = ~(sourceMask << shift);
return target & targetMask | (source & sourceMask) << shift;
}
public static T PartialRead(T target, int shift, int limit)
{
if (shift < 0)
{
shift = 32 + shift;
}
if (limit < 0)
{
limit = 32 + limit;
}
var sourceMask = ~(T.MaxValue << limit) & T.MaxValue;
var targetMask = sourceMask << shift;
return (target & targetMask) >> shift;
}

private static int BitsSize = NumericType<T>.BitsSize;

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions