How to convert from string to hex number

Hello,

I have a requirement for passing a hex value like this to a function.

Example code:
my $ipmbAddress = getIpmbAddress(...); ## returns 82

getDeviceID($ip, $ipmbAddress);

Here in the above code, the getDeviceID() fucntion will accept only
0x82 (hex number). How to convert the number 82 to 0x82 (Note that
this should not be as string)

I tried the following but not working properly.
$ipmbAddress = "0x".$ipmbAddress;
$ipmbAddress = hex("$ipmbAddress");
$ipmbAddress = sprintf(0x%0x, $ipmbAddress);
getDeviceID($ip, $ipmbAddress);


Please help.

Thanks,
DineshK
===========

0
dinesh_rmn
8/17/2007 6:53:46 AM
perl.beginners 29360 articles. 3 followers. Follow

2 Replies
587 Views

Similar Articles

[PageSpeed] 22

dinesh wrote:
> I have a requirement for passing a hex value like this to a function.
> 
> Example code:
> my $ipmbAddress = getIpmbAddress(...); ## returns 82
> 
> getDeviceID($ip, $ipmbAddress);
> 
> Here in the above code, the getDeviceID() fucntion will accept only
> 0x82 (hex number). How to convert the number 82 to 0x82 (Note that
> this should not be as string)

I think it must be a string, or else Perl will convert it to decimal 
whether you like it or not...

     my $num = 0x82;
     print "$num\n";  # prints 130

So if the function expects a hex value, you'd better pass it as a string.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
0
noreply
8/17/2007 10:48:54 AM
On Aug 17, 11:48 am, nore...@gunnar.cc (Gunnar Hjalmarsson) wrote:
> dinesh wrote:
> > I have a requirement for passing a hex value like this to a function.
>
> > Example code:
> > my $ipmbAddress = getIpmbAddress(...); ## returns 82
>
> > getDeviceID($ip, $ipmbAddress);
>
> > Here in the above code, the getDeviceID() fucntion will accept only
> > 0x82 (hex number). How to convert the number 82 to 0x82 (Note that
> > this should not be as string)
>
> I think it must be a string, or else Perl will convert it to decimal
> whether you like it or not...
>
>      my $num = 0x82;
>      print "$num\n";  # prints 130
>
> So if the function expects a hex value, you'd better pass it as a string.

To put it another way what _precisely_ does getDeviceID expect?
There's no such thing as "a hex number" or a "decimal number". There
are just numbers and representations of them.

      my $num = 0x82;

or

      my $num = 130;

These will set $num to the same value - which is just a number (well
an integer actually). If you want to claim it has any base then it's
base-2 because that's what the hardware uses. But really it's just an
number.

As soon as I use $num in a string context then $num will become a
"dualvar" with the string value '130' in addition to the numeric
value.

0
nobull67
8/17/2007 5:29:33 PM
Reply:

Similar Artilces:

how to convert hex string to hex bytes?
Hi I've been trying and haven't found a solution for this yet and hopefully some of you can give me a direction to solve this problem. I have a string in hex representation i.e, 64 chars 'AB23FFFE.....' How can I convert it to 32 chars String where each byte is $AB $23 $FF $FE .... ? Even if I do it manually, can I store the hex(non ASCII) to String? Thanks for looking!! edwin wrote: > I have a string in hex representation i.e, 64 chars 'AB23FFFE.....' > How can I convert it to 32 chars String where each byte is $AB $23 $FF > $FE .... ? Th...

convert string to number
Hello, if I use the sprintf function it would give me a number STRING, but = not number, so I have to trick the string to become number by adding and su= btracting the number with 1. Is there a better way than this ? I want it to= be a number data type and not string.=0A=0Ae.g =0A=0Amy $strNumber =3D spr= intf("%04d", 123);=0Amy $number =3D $strNumber + 1 - 1; # to trick Perl to = convert to number datatype instead of string. =0A=0A=0AThanks,=0A=0AWilliam= =0A=0ASend instant messages to your online friends http://uk.messenger.yaho= o.com On Sun, Jun 15, 2008 at 8:09 PM, Wi...

Convert a string to number
Hi. I want to set a value such as 1.5 or 10 to a text box in a report datawindow at the run time. The value will come from the user before he/she runs the report. How do I convert this string in the text box to a number that will be used for further computation at the summary band? I tried number() function, but it requires a real string and refuses to accept a variable or a column name. Thanks in advance for any help. Jian Kuang If the value comes from the user, it would be in the form of a Retrieve Argument. You can refer to the retrieve argument in the computed field for...

Convertion numbers to strings
Hello! I have some numbers in data type "Numeric". The task is to write expression wich combines prefix, number and suffix. The number must have no spare zero's on tale. Linke in example: "NDS 20%" "SN 1.5%" "ANT 0.25%" The slyboot server makes all the numbers with the same length of fract. part. like "20.00000" and I couldn't cope with this for two weeks already. I don't know of a way to do that in SQL Anywhere. -- Jim Egan [TeamPS] Dealer Solutions, Inc. Houston, TX See you at the Powersoft User Confer...

Converting string to Hex
I'm trying to convert a single character, into a Hex value, and compare. Here's my code: dim int as integer int = Integer.Parse(messages.Substring(x, 1), System.Globalization.NumberStyles.HexNumber) If int = &H0 Or int = &HC Then 'Do stuff end if Unfortunately, this causes an error with the character I'm trying to catch. Does anyone have any ideas? int = Integer.Parse(messages.Substring("x", 1), System.Globalization.NumberStyles.HexNumber) View My Blog Download My URL Rewriter and Reverse ProxyOnly $9.95/month, ASP.NET, 2GB & SQL 2005...

Converting a string to a number
Hello everyone, first post and all that, i got a bit of a problem. First off, the DB information: id: autonumber score: text Both these feilds in the database are numerical, however, the score is used as a text feild, the id an autonumber. When i use a querystring to pass the score over to another page, so that the page produces only information with that perticular score matching, it works. When i try to use the ID number, i get a case miss match. I can only fathom that this is because its an autonumber. However, i need to keep the DB design as it is, as when i add a ne...

Convert String to Number
I am running PB 7.03 build 10047 on Windows 2000. How do I convert a string value to number in the DataWindow script? I can convert number to string using String(ll_value), but how do I do the reverse? The help file says I should be able to use Number(ls_value), but the error checker tells me that is an unknown function. Thanks for your help. dec('123') or long('123') or integer('123') -- Kim Berghall Sisu Group, Inc. remove no_spam. no_spam.kberghall@sisugrp.com www.sisugrp.com <Scott_Emery> wrote in message news:72D1C6C14C517376005C20...

converting HEX to numbers
I need to call Win API methods from PB and I have an example of how they do it in VB. So I am converting the code to PB. However, there are variable declarations that I need help with: HOW CAN I CONVENRT THESE HEX NUMBERS INTO REAL NUMBERS TO DECLARE IN PB? e.g. &H20 is equal to what in PB? constant integer DT_RIGHT = &H2 constant integer DT_SINGLELINE = &H20 constant integer DT_TABSTOP = &H80 constant integer DT_TOP = &H0 constant integer DT_VCENTER = &H4 constant integer DT_WORDBREAK = &H10 constant integer PS_ENDCAP_FLAT = &H200 ...

convert string to number?
Hi, I have a problem where a number read from a file is being treated as a string by perl (I think!). I am using the module RSPerl which is an interface between Perl and the statistical language R. When i read a column of numbers from a file and pass it to the perl/R function i get an "invalid 'type' (character) of argument" error. The reason i think this is a problem on the Perl side is shown by this pseudocode: while(<FILE>){ ... stuff to extract $value from each row ... push(@list1, $value); } @list2 = (100.2, 232.333, 344.2); # these ...

Convert a String to a Number
How can i convert a character to a number, so that the result is only numerical digits, and would always be the same, besides 26 (plus non-alpha characters) if-then statements. like, A = 1 and A always equals 1 so if I had the string:  1234A after converting, I would get the result:  12341 A doesn't necessarily have to = 1, or even a single digit.  It just has to equal a numerical... number. perhaps you can do something like this.  Store your letters in an array A and maintain a cooresponding array B that has the numeric equivalent you would want to repla...

How to convert MemoryStream string to Hex?
I'm doing some encryption and, normally would return a baes 64 string but it's causing issues with URLs, so we are going to use hex strings instead....but I'm having an issue... Instead of:Return Convert.ToBase64String(ms.GetBuffer(), 0, CInt(ms.Length)) I'd like to return a hex string... I need a pointer here....thanks..... Dim myNumber as integer = 'Get your Number from the buffer Dim HexString as string = myNumber.tostring("X")Bryan SampicaAuction Site StarterKit |My Blog The tough part is the "get your number from the buffer" part.... That's what I don't get/know. I'm trying to...

How do I convert strings to floating number?
Hi there, I have a simple problem that I'm sure has been asked before (so why not again ;)) I have a list like this: 1e-100 2e-100 1e-45 5e-10 1 10 20 and want to make correct assignments: 1e-100 SMALL 2e-100 SMALL 1e-45 BIGGER 5e-10 BIGGER 1 BIGGER 10 BIG 20 BIG But with this code while (<>) { chomp; if ($_ lt 1e-50) { print "$_\t SMALL\n"; } elsif (($_ gt 1e-50) && $_ lt 5) { print "$_\t BIGGER\n"; } elsif ($_ gt 5) { print "$_\t BIGGEST\n"; } I only get ...

Convert string to number #2
Hey all, I have got a text field in the summary band in a report datawindow which I want to set to a value at runtime and the value will come from the user. The value will be used for further addition and substraction. How do I convert this value from a string to a number? Thanks in advance for any help. Jian Kuang Depending on the scale or type of number, you can use Dec ( ), Long ( ), Double ( ), Real ( ), or Integer ( ). All of them call for a string or blob argument. Jian Kuang <jkuang@vitinc.com> wrote in message news:3757DC4F.41131683@vitinc.com... Hey a...

how to convert a number to string in SQL?
I search the help for T-sql, still don't know how to convert a number, for example 12345 to a string with formating like 12,345 Thanks for your help. The best place to do such formatting is in the front end, not at the database level.That being said, you could use a combination of the CONVERT and CAST functions (see CAST and CONVERT) to cast the number as a money type, then convert it to a varchar, and then strip off the decimal point and 2 0's at the end:DECLARE @test intSELECT @test = 12345SELECT REPLACE(CONVERT(varchar(50), CAST(@test AS money), 1),'.00','')Or, you could make use of a ...

Web resources about - How to convert from string to hex number - perl.beginners

File:Convert to SVG and move to Commons.svg - Wikipedia, the free encyclopedia
As a courtesy (but not a requirement), please e-mail me or leave a note on my talk page if you use this image outside of Wikipedia. Thanks! As ...

Facebook Co-Founder Dustin Moskovitz Sells 450K Shares, Converts 7M More
The great Facebook stock sale frenzy continues on with a report that Co-Founder Dustin Moskovitz unloaded 450,000 shares in the social network ...

Facebook Announces “App2User” Liquidity Program for Merchants to Convert Rewards Points into Credits
... for Credits, just announced a new Credits program called “App2User,” designed to enable merchants and loyalty program operators to convert their ...

How to Convert Leads Into Buying Customers - The 9 Step Sales Process EVERYONE Should Use
... School of Business in Toronto on the topics of Sales and Entrepreneurship. I shared with them the sales process that I find How to Convert Leads ...

Bitcoin : Should I convert my savings to Bitcoin?
Answer (1 of 7): You should think of this question as "Should I invest all my savings in Bitcoin?", and not "Should I have my savings denominated ...

Convertizo 2 - Convert Units and Currency in Style on the App Store on iTunes
Get Convertizo 2 - Convert Units and Currency in Style on the App Store. See screenshots and ratings, and read customer reviews.

Catholics should not convert Jews, says Vatican, in push against anti-Semitism
... 50 years since the Vatican's repudiation of the concept of Jewish guilt for Jesus' death.  Vatican City: Catholics should not try to convert ...

Opinion: These 5 things made me a happy iPad Pro convert
... like I needed a bigger device. But after three weeks with my iPad Pro, several things have changed my mind, and I’m officially a happy convert ...

$100 device converts all your film to digital photos
... still on film negatives. Today, we've got the perfect Amazon Cyber Week deal for you: A Wolverine F2D Mighty 20MP 7-in-1 Film to Digital Converter ...

"ISIS 'ranks' the women, considering foreign women and converts to be especially 'valuable.' "
"According to French journalist Anna Erelle’s recent exposé , ISIS foreign fighters prefer foreign women and converts because the jihadists find ...

Resources last updated: 12/18/2015 3:25:20 AM