Skip Menu |

This queue is for tickets about the Bit-Vector CPAN distribution.

Report information
The Basics
Id: 39714
Status: rejected
Worked: 15 min
Priority: 0/
Queue: Bit-Vector

People
Owner: Nobody in particular
Requestors: Stephen.Gray [...] maxim-ic.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Bug - Must allocate extra space to receive valid data in conversion from hex to decimal
Date: Tue, 30 Sep 2008 12:57:54 -0500
To: "bug-Bit-Vector [...] rt.cpan.org" <bug-Bit-Vector [...] rt.cpan.org>
From: Stephen P Gray <Stephen.Gray [...] maxim-ic.com>
When declaring a new_Hex item one must pad at least one extra bit in the size field or when converting to decimal the value returned is invalid. Show quoted text
>>> Code >>>
my $hex = '966104526fe7d8baac32d27124a467b8'; my $vec = Bit::Vector->new_Hex(128, $hex); print "128 bits - $hex => " . $vec->to_Dec() . "\n"; my $vec2 = Bit::Vector->new_Hex(129, $hex); print "129 bits - $hex => " . $vec2->to_Dec() . "\n"; <<< End Code <<< Show quoted text
>>> Output >>>
128 bits - 966104526fe7d8baac32d27124a467b8 => -140394427096942342042315520958275491912 129 bits - 966104526fe7d8baac32d27124a467b8 => 199887939823996121421059086473492719544 <<< End Output <<< OS: SunOS caddo 5.8 Generic_117350-36 sun4u sparc Perl::Version: 5.8.1 Bit::Vector::Version: 6.4 Stephen P. Gray Maxim Integrated Products Test Engineer I (972) 371-4631 Stephen.Gray@maxim-ic.com
On Tue Sep 30 14:00:46 2008, Stephen.Gray@maxim-ic.com wrote: Show quoted text
> When declaring a new_Hex item one must pad at least one extra bit in > the size field or when converting to decimal the value returned is > invalid. >
> >>> Code >>>
> my $hex = '966104526fe7d8baac32d27124a467b8'; > my $vec = Bit::Vector->new_Hex(128, $hex); > print "128 bits - $hex => " . $vec->to_Dec() . "\n"; > > my $vec2 = Bit::Vector->new_Hex(129, $hex); > print "129 bits - $hex => " . $vec2->to_Dec() . "\n"; > > <<< End Code <<< >
> >>> Output >>>
> 128 bits - 966104526fe7d8baac32d27124a467b8 => > -140394427096942342042315520958275491912 > 129 bits - 966104526fe7d8baac32d27124a467b8 => > 199887939823996121421059086473492719544 > <<< End Output <<< > > OS: SunOS caddo 5.8 Generic_117350-36 sun4u sparc > Perl::Version: 5.8.1 > Bit::Vector::Version: 6.4 > > Stephen P. Gray > Maxim Integrated Products > Test Engineer I > (972) 371-4631 > Stephen.Gray@maxim-ic.com
This is the intended and documented behaviour, due to the internal two's complement representation of numbers, the switching between unsigned and signed semantics and the lack of "sign extension" in the from/to_Hex methods (the "Copy" method does that, however - see the manual!). CODE: #!perl -w use Bit::Vector; my $hex = '966104526fe7d8baac32d27124a467b8'; my $vec = Bit::Vector->new_Hex(128, $hex); print "128 bits - $hex => " . $vec->to_Dec() . " " . $vec->to_Hex() . "\n"; my $vec2 = Bit::Vector->new_Hex(129, $hex); print "129 bits - $hex => " . $vec2->to_Dec() . " " . $vec->to_Hex() . "\n"; $vec2->MSB(1); print "129 bits - $hex => " . $vec2->to_Dec() . " " . $vec->to_Hex() . "\n"; OUTPUT: 128 bits - 966104526fe7d8baac32d27124a467b8 => -140394427096942342042315520958275491912 966104526FE7D8BAAC32D27124A467B8 129 bits - 966104526fe7d8baac32d27124a467b8 => 199887939823996121421059086473492719544 966104526FE7D8BAAC32D27124A467B8 129 bits - 966104526fe7d8baac32d27124a467b8 => -140394427096942342042315520958275491912 966104526FE7D8BAAC32D27124A467B8
Sorry, there was a slight glitch in the code and output: CODE: #!perl -w use Bit::Vector; my $hex = '966104526fe7d8baac32d27124a467b8'; my $vec = Bit::Vector->new_Hex(128, $hex); print "128 bits - $hex => " . $vec->to_Dec() . " " . $vec->to_Hex() . "\n"; my $vec2 = Bit::Vector->new_Hex(129, $hex); print "129 bits - $hex => " . $vec2->to_Dec() . " " . $vec2->to_Hex() . "\n"; $vec2->MSB(1); print "129 bits - $hex => " . $vec2->to_Dec() . " " . $vec2->to_Hex() . "\n"; OUTPUT: 128 bits - 966104526fe7d8baac32d27124a467b8 => -140394427096942342042315520958275491912 966104526FE7D8BAAC32D27124A467B8 129 bits - 966104526fe7d8baac32d27124a467b8 => 199887939823996121421059086473492719544 0966104526FE7D8BAAC32D27124A467B8 129 bits - 966104526fe7d8baac32d27124a467b8 => -140394427096942342042315520958275491912 1966104526FE7D8BAAC32D27124A467B8
Sorry, this bug report is rejected (no bug).