Skip to content

Commit

Permalink
Fix signedness of high/low part getters
Browse files Browse the repository at this point in the history
  • Loading branch information
olafkryus committed Apr 4, 2020
1 parent 46b20eb commit 0baaf70
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 68 deletions.
20 changes: 0 additions & 20 deletions src/DataType/Byte.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,4 @@ public function __construct(string $value, int $endianness = BinaryValue::ENDIAN

parent::__construct($value, $endianness);
}

/**
* @return int
*/
public function getHighNibble(): int
{
$value = $this->toInt();

return ($value >> 4) % 16;
}

/**
* @return int
*/
public function getLowNibble(): int
{
$value = $this->toInt();

return $value % 16;
}
}
24 changes: 0 additions & 24 deletions src/DataType/Dword.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,4 @@ public function __construct(string $value, int $endianness = BinaryValue::ENDIAN

parent::__construct($value, $endianness);
}

/**
* @return Word
* @throws \Exception
*/
public function getHighWord(): Word
{
$value = $this->__toString();
$endianness = $this->getEndianness();

return new Word(substr($value, $endianness === BinaryValue::ENDIANNESS_LITTLE_ENDIAN ? 2 : 0, 2), $endianness);
}

/**
* @return Word
* @throws \Exception
*/
public function getLowWord(): Word
{
$value = $this->__toString();
$endianness = $this->getEndianness();

return new Word(substr($value, $endianness === BinaryValue::ENDIANNESS_LITTLE_ENDIAN ? 0 : 2, 2), $endianness);
}
}
20 changes: 20 additions & 0 deletions src/DataType/UnsignedByte.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,24 @@ public function __construct(string $value, int $endianness = BinaryValue::ENDIAN

parent::__construct($value, $endianness, false);
}

/**
* @return int
*/
public function getHighNibble(): int
{
$value = $this->toInt();

return ($value >> 4) % 16;
}

/**
* @return int
*/
public function getLowNibble(): int
{
$value = $this->toInt();

return $value % 16;
}
}
24 changes: 24 additions & 0 deletions src/DataType/UnsignedDword.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,28 @@ public function __construct(string $value, int $endianness = BinaryValue::ENDIAN

parent::__construct($value, $endianness, false);
}

/**
* @return UnsignedWord
* @throws \Exception
*/
public function getHighWord(): UnsignedWord
{
$value = $this->__toString();
$endianness = $this->getEndianness();

return new UnsignedWord(substr($value, $endianness === BinaryValue::ENDIANNESS_LITTLE_ENDIAN ? 2 : 0, 2), $endianness);
}

/**
* @return UnsignedWord
* @throws \Exception
*/
public function getLowWord(): UnsignedWord
{
$value = $this->__toString();
$endianness = $this->getEndianness();

return new UnsignedWord(substr($value, $endianness === BinaryValue::ENDIANNESS_LITTLE_ENDIAN ? 0 : 2, 2), $endianness);
}
}
24 changes: 24 additions & 0 deletions src/DataType/UnsignedWord.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,28 @@ public function __construct(string $value, int $endianness = BinaryValue::ENDIAN

parent::__construct($value, $endianness, false);
}

/**
* @return UnsignedByte
* @throws \Exception
*/
public function getHighByte(): UnsignedByte
{
$value = $this->__toString();
$endianness = $this->getEndianness();

return new UnsignedByte($value[$endianness === BinaryValue::ENDIANNESS_LITTLE_ENDIAN ? 1 : 0], $endianness);
}

/**
* @return UnsignedByte
* @throws \Exception
*/
public function getLowByte(): UnsignedByte
{
$value = $this->__toString();
$endianness = $this->getEndianness();

return new UnsignedByte($value[$endianness === BinaryValue::ENDIANNESS_LITTLE_ENDIAN ? 0 : 1], $endianness);
}
}
24 changes: 0 additions & 24 deletions src/DataType/Word.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,4 @@ public function __construct(string $value, int $endianness = BinaryValue::ENDIAN

parent::__construct($value, $endianness);
}

/**
* @return Byte
* @throws \Exception
*/
public function getHighByte(): Byte
{
$value = $this->__toString();
$endianness = $this->getEndianness();

return new Byte($value[$endianness === BinaryValue::ENDIANNESS_LITTLE_ENDIAN ? 1 : 0], $endianness);
}

/**
* @return Byte
* @throws \Exception
*/
public function getLowByte(): Byte
{
$value = $this->__toString();
$endianness = $this->getEndianness();

return new Byte($value[$endianness === BinaryValue::ENDIANNESS_LITTLE_ENDIAN ? 0 : 1], $endianness);
}
}

0 comments on commit 0baaf70

Please sign in to comment.