LinuxQuestions.org
Visit Jeremy's Blog.
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 02-05-2007, 08:51 AM   #1
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Rep: Reputation: 30
display in hex + perl + non ASCII characters


Hi All,

How to display the hex value of non-ASCII characters.

Below code doesnt work!!

Code:
#! /opt/third-party/bin/perl
                                                                                 
$var='é';
print ord($var);
  $da = sprintf("%lx", $var);
  print "\n" . $da . "\n";
                                                                                 
exit 0

Thanks!
 
Old 02-05-2007, 11:49 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Hard to know for sure what you were expecting, but does this look more like what you want?
Code:
#! /opt/third-party/bin/perl
  $var='é';
  print ord($var);
  $da = sprintf("%lx", ord($var));
  print "\n" . $da . "\n";
exit 0
 
Old 02-05-2007, 10:52 PM   #3
kshkid
Member
 
Registered: Dec 2005
Distribution: RHEL3, FC3
Posts: 383

Original Poster
Rep: Reputation: 30
With the code I had posted I wont be able to retrieve both the bytes of utf8 encoded character.

Only the first byte of the é would be returned.

I need a methodology to return both the bytes.

é - Since its range is greater than 0x7F it would be encoded in 2 bytes.

Hope I had made my requirement clear
 
Old 02-06-2007, 05:08 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Hmmm. I now understand your question, and even after a bit of googling, I regret that I don't have any good answer. I am sorry to have bumped you off the 'zero-reply' list. Perhaps you should start a new thread (which I will leave unsullied), and include some of the language from pages such as http://www.justatheory.com/computers...f8_trials.html
or http://perl.net.au/wiki/Unicode in your subject line.
--- rod.
 
Old 02-06-2007, 05:48 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,426

Rep: Reputation: 2786Reputation: 2786Reputation: 2786Reputation: 2786Reputation: 2786Reputation: 2786Reputation: 2786Reputation: 2786Reputation: 2786Reputation: 2786Reputation: 2786
These would be the guys to ask: http://www.perlmonks.org/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[bash] ASCII to HEX and hex to ascii ////// Programming 17 05-08-2018 10:55 PM
How do i write to a serial port (modem) in ascii or hex directly? Taliesin.duchaos Linux - Networking 6 04-21-2006 09:31 AM
Convert characters to hex values in perl pjz Programming 3 12-08-2005 09:35 AM
Binary to Hex Ascii converter carboncopy Slackware 1 05-28-2004 10:09 AM
ascii characters lakshman Linux - General 1 03-14-2003 12:28 PM

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