473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to represend a hex-string in perl ex: aa 01

1
how to represend a hex-string in perl ex: aa 01
Jun 22 '07 #1
1 1772
prn
254 Expert 100+
Hi Aagal,

I'm not sure what you are asking here. Do you want to know how to represent a string like aa01 as a hexadecimal number in your code?
Expand|Select|Wrap|Line Numbers
  1. my $number = 0xaa01;
Or did you want to print the number in hexadecimal form?
Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/perl
  2. use strict;
  3. my $number = 0xaa01;
  4. print "Number (in decimal form) is $number\n";
  5. print "Number (as hex digits only) is ", sprintf("%1x",$number), "\n";
  6. print "Number (as a C-style hex number) is ", sprintf("0x%1x",$number), "\n";
  7.  
which prints
Expand|Select|Wrap|Line Numbers
  1. Number (in decimal form) is 43521
  2. Number (as hex digits only) is aa01
  3. Number (as a C-style hex number) is 0xaa01
Or was there something else you had in mind?

Best Regards,
Paul
Jun 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: DvGrimm | last post by:
Any help would be very, very much appreciated... I've been searching the net (google) for 4 days now trying to find a php function to convert hex to floating point. I'm converting old...
4
by: Paul | last post by:
Hi, (First apologies if this is not the most relevant place to post this but I wasn't sure of where was and I am writing my app in VB.) I'm attempting to parse a binary file for which I have...
16
by: Delali Dzirasa | last post by:
I would have a number packed with its hex representation of the integer below is some sample code of what is being done. int value = 20; //in hex it is 0x14 AddData (value); .. .. ..
7
by: Steven D'Aprano | last post by:
hex() of an int appears to return lowercase hex digits, and hex() of a long uppercase. >>> hex(75) '0x4b' >>> hex(75*256**4) '0x4B00000000L' By accident or design? Apart from the aesthetic...
6
by: Luther Baker | last post by:
Hi, This doesn't do what I expect. int t = 27; std::cout << "myHex: '" << std::ios::hex << t << "'" << std::endl; std::cout.setf(std::ios::hex); std::cout << "moreHex: '" << t << "'" <<...
2
by: Generic Usenet Account | last post by:
What exactly is the difference between the hex manipulator and the following statement: cout.setf(ios_base::hex)? According to Stroustrup, Third Edition, Section 21.4.4, "once set, a base is...
13
by: Hako | last post by:
I try this command: >>> import string >>> string.atoi('78',16) 120 this is 120 not 4E. Someone can tell me how to convert a decimal number to hex number? Can print A, B, C,DEF. Thank you.
9
by: Niels Jensen | last post by:
Hi All, I'm desperately looking for help regarding the following: I need to make a hexmap in it's own scrollable window on a form, when I say hex map I mean a graphical hexagon surrounded by...
5
by: kuukelekuu | last post by:
I need to convert ascii chars to hex chars. I searched the internet, found hex to ascii, but nowhere is there a ascii to hex method created by anyone. Can anyone help me with that? Chears
28
by: James Brown | last post by:
All, I have a series of characters which I need to convert to integer values. Each character is read in turn from a function 'nextch', and hex-digits are identified by the isxdigit function - so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.