Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with dec data to bin data translator in Perl

Status
Not open for further replies.

davyzhu

Advanced Member level 1
Advanced Member level 1
Joined
May 23, 2004
Messages
494
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,298
Location
oriental
Activity points
4,436
Hi all,

I want to write a dec data to bin data translator.
But I found the $dec_pack in the program don't print "A signed integer value" as the pack manual said. Why? Thanks!

#------------------------------------------------
use strict;
use warnings;


my $dec = 1234;
my $bin;

$bin = dec2bin($dec);

print 'bin is ',$bin,"\n";

sub dec2bin {
my $dec_shift = shift;
print 'dec_shift is ',$dec_shift, "\n";

my $dec_pack = pack("i", $dec_shift);
print 'dec_pack ',$dec_pack, "\n";

return unpack('B32', $dec_pack);
}
#----------------------------------------------------

Best regards,
Davy
 

umairsiddiqui

Full Member level 2
Full Member level 2
Joined
Apr 13, 2004
Messages
143
Helped
7
Reputation
14
Reaction score
1
Trophy points
1,298
Location
Sweden
Activity points
1,434
[Perl] pack problem

if just want to convert dec value to bin value consider "sprintf"
 

    davyzhu

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top