/
NikolayIvkin
/
tutorials1
Обзор
Документация
Войти
/
NikolayIvkin
/
tutorials1
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
core-java-modules/core-java-numbers-conversions-2/inttounsignedbyte/IntToUnsignedByteUnitTest.java
27 строк
769 B
MohamedHelmyKassab
Update IntToUnsignedByteUnitTest.java (#16855)
17 июн 2024, 20:33
Не верифицирован
17 июн 2024, 20:33
2b3d9eb
Код
Авторство
О чём код?
package com.baeldung.inttounsignedbyte; import org.junit.Test; import java.nio.ByteBuffer; import static org.junit.jupiter.api.Assertions.assertEquals; public class IntToUnsignedByteUnitTest { int value = 200; @Test public void givenInt_whenUsingTypeCastingAndBitMasking_thenConvertToUnsignedByte() { byte unsignedByte = (byte) (value & 0xFF); assertEquals(value, Byte.toUnsignedInt(unsignedByte)); } @Test public void givenIntInRange_whenUsingByteBuffer_thenConvertToUnsignedByte() { int value = 200; ByteBuffer buffer = ByteBuffer.allocate(4).putInt(value); byte unsignedByte = buffer.array()[3]; assertEquals(value, Byte.toUnsignedInt(unsignedByte)); } }