Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace 32 with BitsSize #106

Open
Konard opened this issue Feb 8, 2023 · 0 comments
Open

Replace 32 with BitsSize #106

Konard opened this issue Feb 8, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@Konard
Copy link
Member

Konard commented Feb 8, 2023

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;

@Konard Konard added the bug Something isn't working label Feb 8, 2023
@DdeadliestT DdeadliestT self-assigned this Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants