从converting an array of signed bytes to unsigned bytes扩展,如果没有使用Lambdas的笨重循环,这可以更优雅地执行吗?所以,
已签名byte[]
- > unsigned int[]
我注意到没有Arrays.stream(byte[])
。
答案 0 :(得分:0)
当然,你可以:
int[] unsigned = IntStream.range(0, signed.length)
.map(i -> signed[i] & 0xFF)
.toArray();
其中signed表示字节数组。
答案 1 :(得分:0)
是的,你可以使用def check_plan_expiration_date():
user_exp_date = user_trainingplan.expiration_date
now = datetime.now(timezone.utc)
if user_exp_date <= now:
user_trainingplan.expiration_date = datetime.now(timezone.utc)+timedelta(days=7)
user_trainingplan.save()
else:
return user_exp_date
来实现它:
IntStream
有关详细信息,请参阅this answer。
答案 2 :(得分:0)
你可以这样做。
int[] unsigned = IntStream.range(0, bytes.length)
.map(i -> 0x7F & bytes[i])
.toArray();