LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-07-2005, 02:18 PM   #1
pjz
Member
 
Registered: Sep 2003
Posts: 71

Rep: Reputation: 15
Convert characters to hex values in perl


I'm using Red Hat 9.0.

This is a perl programming question.

I'm opening up a file that consists of a series of
bytes. I'd like to be able to deal with the character
stream as a series of hex values, not as characters.

Is there any way that I can convert a character into it's hex equivalent. In C, I can use the function
atoi(). I'd like to know if Perl supplies anything
like this function.

thanks
pjz
 
Old 12-07-2005, 05:00 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
printf() with x as the format specifier....
 
Old 12-07-2005, 09:06 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
According to the Camel book, its:
sprintf("%lx", $num); # that's a lowercase 'L', not a one (1)
 
Old 12-08-2005, 08:35 AM   #4
pjz
Member
 
Registered: Sep 2003
Posts: 71

Original Poster
Rep: Reputation: 15
Found the answer

Found the answer. Thanks big to those who replied.

The way to do this is:

$foo = ord($bar);

where $bar is a character, and $foo is a number.

pjz
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert a float to its binary or hex representation in Python? zero79 Programming 1 09-01-2005 10:19 AM
How to convert a float to its binary or hex representation in Python? zero79 Linux - Software 1 08-29-2005 09:30 PM
Convert from hex to dec Ephracis Programming 3 05-30-2005 10:42 AM
Convert special characters in text file nyk Linux - Software 1 01-05-2005 03:20 PM
seperating values using perl pantera Programming 3 05-26-2004 12:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration