Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: BIN to HEX

by Roger (Parson)
on Aug 22, 2006 at 07:01 UTC ( #568786=note: print w/replies, xml ) Need Help??

in reply to BIN to HEX

You could first open the file, then read the byte in from the file handle, then inspect the byte.

# open a file open MYFILE, '<myfile.bin' or die 'can not open file'; # read a byte my $byte; read MYFILE, $byte, 1; # do perldoc -f read to see full doco # check the byte if ($byte > 0x30) { print "Byte is greater than 0x30\n"; } else { print "Byte is less than or equal to 0x30\n"; } # close the file close MYFILE;

Replies are listed 'Best First'.
Re^2: BIN to HEX
by eyepopslikeamosquito (Chancellor) on Aug 22, 2006 at 11:26 UTC

    If the file is binary, you should add:

    binmode MYFILE;
    right after the open. Also the line:
    if ($byte > 0x30) {
    should read:
    if (ord($byte) > 0x30) {

Re^2: BIN to HEX
by betterworld (Curate) on Aug 22, 2006 at 11:15 UTC
    if ($byte > 0x30) {
    Shouldn't that be ord($byte) > 0x30?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://568786]
[Discipulus]: goodby stress..
LanX you always reminded me of Sean Connery. ..
shmem .oO( someday I'll do something... and then I'll make it big. Now is the time! )
[LanX]: don't forget to flush the water
[shmem]: the day will come when LanX hits the fan
[Discipulus]: did you remember to commit?

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2018-04-24 11:29 GMT
Find Nodes?
    Voting Booth?