由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - perl sprintf question converting dec to hex
相关主题
how to convert str to doublewhy int** cannot convert to const int** ?
New "KENG" about Perl.How to conver CString to long long type?
how to convert GMT to timestamp of the computer's current timeHelp with a c++ const variable
how to print 2 exponential digits in windows by using Perl在C里面怎么验证一个input数字是不是超过int的范围?
easy problem coconutHow to write a VB Macro to convert text to hyperlink in Excel
Perl Q: how to convert integer to MAC addressC, how is a string cast into a int?
大家面试FLAG的时候,用什么语言how to convert an integer to a widestring
is it possible use VC 6.0 library file in .netconvert mapped drive letter to full path in vbscript (转载)
相关话题的讨论汇总
话题: macaddress话题: sprintf话题: perl话题: 06x话题: converting
进入Programming版参与讨论
1 (共1页)
w**2
发帖数: 724
1
hi i have this line,
$MACAddress = sprintf("%06x", $MACAddress);
1. when $MACAddress was -1, this line converts it to ffffffffffffffff
instead of ffffffff, i'm on a 32-bit linux pc.
why ?
2. in my code, i need to write $MACAddress twice.
how to use some shortcut e.g. $1 ?
Thanks !
BTW, i LOVE Perl, :)
e*******o
发帖数: 4654
2
1.
➜ perl -MDevel::Peek -E 'Dump(-1)'
SV = IV(0x15f02a0) at 0x15f02b0
REFCNT = 1
FLAGS = (PADTMP,IOK,READONLY,pIOK)
IV = -1
this show -1 is stored as IV internally.
➜ perl -V:ivsize
ivsize='8';
the unit is bytes, so size in bit
ivszie * 8 = 64 .
2. same with C, 1$
http://perldoc.perl.org/functions/sprintf.html
w**2
发帖数: 724
3
大牛,请问如何把-1 打印成 ffffffff ?
别的都已经是8个字了,就这个-1是16个字。
谢谢!

【在 e*******o 的大作中提到】
: 1.
: ➜ perl -MDevel::Peek -E 'Dump(-1)'
: SV = IV(0x15f02a0) at 0x15f02b0
: REFCNT = 1
: FLAGS = (PADTMP,IOK,READONLY,pIOK)
: IV = -1
: this show -1 is stored as IV internally.
: ➜ perl -V:ivsize
: ivsize='8';
: the unit is bytes, so size in bit

n*******e
发帖数: 4894
4
只要结果超过8个字符,跟%08没关系了,这是如果不够8个字符前面加0凑足到8个

【在 w**2 的大作中提到】
: 大牛,请问如何把-1 打印成 ffffffff ?
: 别的都已经是8个字了,就这个-1是16个字。
: 谢谢!

e*******o
发帖数: 4654
5
不值得,你看看文档,把 -1 当成特殊情况吧。

【在 w**2 的大作中提到】
: 大牛,请问如何把-1 打印成 ffffffff ?
: 别的都已经是8个字了,就这个-1是16个字。
: 谢谢!

n*******e
发帖数: 4894
6
$MACAddress =sprintf("%.8s" ,(sprintf("%08x", $MACAddress)));
也许这是想要的?如果大于八位,就去掉末尾多余的
$MACAddress = sprintf("%08x", $MACAddress) =~ s/.*(\w{8})$/$1/r;
如果想truncate的是前面的,就用上面这种办法

【在 n*******e 的大作中提到】
: 只要结果超过8个字符,跟%08没关系了,这是如果不够8个字符前面加0凑足到8个
n*******e
发帖数: 4894
7
恩,一般这种情况手动处理一下就好了

【在 e*******o 的大作中提到】
: 不值得,你看看文档,把 -1 当成特殊情况吧。
w**2
发帖数: 724
8
谢谢各位!
f*******n
发帖数: 12623
9
$MACAddress = sprintf("%06x", $MACAddress & 0xffffffff);
1 (共1页)
进入Programming版参与讨论
相关主题
convert mapped drive letter to full path in vbscript (转载)easy problem coconut
Convert a binary tree to a BST... in place..Perl Q: how to convert integer to MAC address
any guys here using py2exe?大家面试FLAG的时候,用什么语言
求个简单的算法is it possible use VC 6.0 library file in .net
how to convert str to doublewhy int** cannot convert to const int** ?
New "KENG" about Perl.How to conver CString to long long type?
how to convert GMT to timestamp of the computer's current timeHelp with a c++ const variable
how to print 2 exponential digits in windows by using Perl在C里面怎么验证一个input数字是不是超过int的范围?
相关话题的讨论汇总
话题: macaddress话题: sprintf话题: perl话题: 06x话题: converting