Perl and binary workings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl and binary workings
# 1  
Old 11-04-2002
Data Perl and binary workings

Perhaps it's me - maybe I'm dumb and am getting this working solution wrong...

I have a binary value 00000011 in $binVal and I want to print the result in denary, so in perl I did as the perldoc -f oct told me to do and added a 0b prefix as so:
Code:
$binVal = "0b" . $binVal;

then I wanted to print the result, so I did:
Code:
print oct( $binVal );

If my binary calculations are right, I should get "3", instead I get "0" - why? where am I going wrong?

Cheers!
# 2  
Old 11-04-2002
I get 3 .....

Code:
$binVal = "000011";
$binVal = "0b" . $binVal;
print oct($binVal);

Smilie
# 3  
Old 11-04-2002
Which version of Perl are you running? Which Unix?
# 4  
Old 11-04-2002
GNU/Linux 2.4.10
perl 5.8.0

I run the three lines exactly as quoted and got 3.
# 5  
Old 11-04-2002
Ok - this is VERY bizarre!!!

I posted my question from work - where I was using a Win98 box and Perl 5.004 (or similar!)

I've just gotten home and have tried the same code on my FreeBSD box using Perl 5.6.1 and it worked perfectly Smilie

Perhaps it was omitted in the Windows version 5.004? Smilie

Thanks for all your help though Smilie
# 6  
Old 11-04-2002
Quote:
Originally posted by WIntellect
Ok - this is VERY bizarre!!!

I posted my question from work - where I was using a Win98 box and Perl 5.004 (or similar!)

I've just gotten home and have tried the same code on my FreeBSD box using Perl 5.6.1 and it worked perfectly Smilie

Perhaps it was omitted in the Windows version 5.004? Smilie

Thanks for all your help though Smilie
This is what I get on my Win32 machine at work when I tested out the previous code:

Code:
D:\>cat test.pl
$binVal = "000011";
$binVal = "0b" . $binVal;
print oct($binVal);

D:\>test.pl
3
D:\>perl -version

This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2001, Larry Wall

Binary build 633 provided by ActiveState Corp. http://www.ActiveState.com
Built 21:33:05 Jun 17 2002


Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Explanation for Scripts Inner Workings Needed

#!/bin/bash n=$l; typeset -a v x=$(< input.dat) check(){ if; then sed 's/Test/Proc/g' file.sh >fl.sh else exit 13 fi } check $n while ; do x=`expr $x -l` v=$x done less fi.sh l>/dev/null&& echo yes || exit 1 echo v= ${v } exit 0 I have file.sh and input.dat in the current... (3 Replies)
Discussion started by: bananasprite
3 Replies

2. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

3. Shell Programming and Scripting

Binary patch using perl

for all who are interested: a bash function scanning all unique strings in FILE that contain a token and replacing it. Furthermore the function demonstrates how to construct a perl command from variables in a script: patchfile() { local -r file="$1" local -r... (1 Reply)
Discussion started by: dodona
1 Replies

4. Shell Programming and Scripting

Convert binary file to csv and then back to the binary format

Hello *nix specialists, Im working for a non profit organisation in Germany to transport DSL over WLAN to people in areas without no DSL. We are using Linksys WRT 54 router with DD-WRT firmware There are at the moment over 180 router running but we have to change some settings next time. So my... (7 Replies)
Discussion started by: digidax
7 Replies

5. Shell Programming and Scripting

Displaying a number in binary using perl

printf FH2" 3'b%b : begin\n",$i; where i is an integer in the loop is displaying 3'b1 : begin expected output was 3'b001 : begin (1 Reply)
Discussion started by: dll_fpga
1 Replies

6. Shell Programming and Scripting

Convert binary to text Perl script

Hello everyone, I have a binary file with a structure unknown. I have found 2 perl scripts that it seems to do the convertion but I get sintactic errors when I run them, may somebody test these 2 scripts please and see if really work? One if from here... (10 Replies)
Discussion started by: Ophiuchus
10 Replies

7. Shell Programming and Scripting

Perl : find perl executable binary

Hi I have an oracle perl script running as cron job across multiple unix servers. The issue is the perl binary is found in multiple directories I use in the start of the script ... #!/usr/bin/perl on some servers the script fails because /usr/bin/perl is not present. Is there a way i can... (4 Replies)
Discussion started by: PrasannaKS
4 Replies

8. Shell Programming and Scripting

capturing C++ binary return status in perl

Hello, I have a C++ binary that runs in my perl script. But, Currently, the binary is doing a core dump and i want to capture the retrun status of the binary to report as an issue. Can you please help me on this. Thanks, Sateesh (1 Reply)
Discussion started by: kotasateesh
1 Replies

9. Shell Programming and Scripting

capturing C++ binary return status in perl

Hello, I have a C++ binary that runs in my perl script. But, Currently, the binary is doing a core dump and i want to capture the retrun status of the binary to report as an issue. Can you please help me on this. Thanks, Sateesh (1 Reply)
Discussion started by: kotasateesh
1 Replies

10. Solaris

compiled binary file gives "cannot execute binary file"

Hi, I have two Solaris machines. 1. SunOS X 5.8 Generic_108528-29 sun4u sparc SUNW,Sun-Blade-1500 2. SunOS Y 5.8 Generic_108528-13 sun4u sparc SUNW,Ultra-60 I am trying to buiild a project on both these machines. The Binary output file compiled on machine 2 runs on both the machines. Where... (0 Replies)
Discussion started by: scgupta
0 Replies
Login or Register to Ask a Question