packing int to hex



  • 1. How to check if a mount point exists.
    Hi: I writing some logs into a directory which is mounted. >df -k 335544320 18471160 317073160 6% /actuate/rawdata > Is there a way to check within perl if the mount point exists before I write? Thanks ray
  • 2. Can I use perl ,write programs in perl without installing it on any computer
    Hi , Can I use perl ,write programs in perl without installing it on any computer? IS there any perl online development simulator exists? Thanks, Vijayshree
  • 3. How to 'conditionally' use a specified module
    Hello everyone, I need to check if one of my variables is true, then use a specific module: my $use_cache = 'no'; if ($use_cache == 'yes'){ use Cache::SizeAwareFileCache; } The problem I have is that no matter if $use_cache is yes or no, Perl always try to evaluate the use of Cache::SizeAwareFileCache at run-time and if I don't have that module installed, it gives me an error: Couldn't find the module "Cache/". Even though I stated clearly that $use_cache = 'no', Perl still reports that Cache::SizeAwareFileCache is not installed. What exactly am I missing here? Is there an easy way to ignore the missing module inside a condition? Thanks --Danny
  • 4. How to detect a file creation
    Hi, I need to write a script that detects when a file is created in a certain directory and then e-mail it. I thought about fam. Problem is the machine is a AIX and it doens't have fam. I think in PERL is possible to do the trick. I don't know in advance the name of the files that are created. Any help would be appreciated. Warm regards, Mio Gamito
  • 5. Question on an error I keep receiving...
    Hi I'm very new to Perl and teaching myself...Running ActiveState port on Windows Server 2003 version 5.8.8 build: 819. I'm writing some very simple scripts to return basic numerical values for learning purposes and keep receiving the below error: panic: utf16_to_utf8: odd bytelen blah, blah, blah.. The line it fails on is: print 25000000, "\n"; I've gotten this same error when trying to return unicode values. Is this environment-related behavior with Perl on Windows? Thanks for helping me further my education.

packing int to hex

Postby junaid » Sun, 25 Dec 2005 14:36:31 GMT

Hi All,
 How can i store integer number (0 <=x<=15) as hexa decimal number in

Re: packing int to hex

Postby Paul Lalli » Mon, 26 Dec 2005 07:01:27 GMT

Perl stores all integers natively.  Why would you want to even attempt
to change that?

Or do you actually mean "How to I obtain the hexidecimal representation
of a number"?

my $hex = sprintf ('%x', $int);

Paul Lalli

Similar Threads:

1.pack and hex

2.KILL INT can not wake up $SIG{INT}

Hi list,

Anyone has such experience? KILL INT pid cannot wake up $SIG{INT}  sub{}.

my code is like;

$SIG{INT} = sub {#load pm}

$SIG{ALRM} = sub {print "Driver $pm is going to sleep... bye.\n"; exit;};

the pm actually has a system call to execute something
sub xxx {


my $tmp = kill "INT", $pid; ## it returns number of processes, eg: 1
cannot wake up the $SIG{INT}  at all after $SIG{ALRM} has been executed.

does system call cause the problem?


3.pack 'C3U*' not same as pack 'C3(xC)*'


I have a small card game. The clients are Java-applets and the
server is written in C, mostly forwarding data from applet to applet.

The message format is:

    1 byte:             Number of unicode chars (s. below)
    2 byte:             Player number
    3 byte:             Event id
    up to 510 bytes:    A Java unicode string

Now I'm trying to rewrite my C-server to perl, because that way
it's easier to add features (syslog, auth against an SQL-db, etc.)

I have problems to understand what would be the best pack-format for
my messages. I have read "perldoc -f pack" numerous times and also
the many O'Reilly books I have, but the best I've come up with is

   pack "C3(xC)*", length $ascii_str, $num, $id, unpack "C*",

for the cases, when I need to send an ASCII string (like an IP address
string) from the server to the Java-applet and thus have to stuff the
upper bytes of that ASCII with zeros (that's why the "x" above).

I wonder, why doesn't pack "C3U*" do the same? Here is a demo:

    # perl -e '$str=pack "C3(xC)*", 4, 0, 14, unpack "C*", "test"; \
        print join " ", unpack "C*", $str'

    4 0 14 0 116 0 101 0 115 0 116

    # perl -e '$str=pack "C3U*", 4, 0, 14, unpack "C*", "test"; \
        print join " ", unpack "C*", $str'

    4 0 14 116 101 115 116

As you see, the stuffing zeros are missing in the second output.
But why? Doesn't "perldoc -f pack" say

    If you don't want this [UTF8] to happen, you can
    begin your pattern with "C0" (or anything else) to force
    Perl not to UTF8 encode your string, and then follow
    this with a "U*" somewhere in your pattern.


PS: Also I wonder, if there are any nicer ways to communicate
    Java-strings to Perl. "perldoc -f pack" mentions "n/..."
    for Java-Strings, but doesn't elaborate. Is it "n/U*" ?

4.Why char** dynamic_string_array(int ROWS, int SIZE) doesn't work properly?

Hi,please help...
It works fine when I define a 2-D array like char code[ROWS][SIZE].
But it won't work when I try to define the array dynamically using a
function. It just crashes.
Does anyone know why?
The compiler i'm using is Dev c++.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int file_length(FILE *file);
void down_string(char *p);
char* issubstring(char *str1,char *str2);
char** dynamic_string_array(int ROWS, int SIZE);

int main(void)
  int row,n,i,coursefound=0,ROWS,SIZE,test;

  FILE *datafile;
  datafile=fopen("3rdyear.csv", "rb");

  printf("Has %d lines\n",ROWS);

  char **Code,**Course,**ClassSize,**Time1,**Time2,**Room,c;
  char search[30];


  for (row=0; row <ROWS; row++) {
  test=fscanf(datafile, "%[^,],%[^,],%[^,],%[^,],%[^,],%[^\n]\n",

  printf("row=%d,scanf converted %d (%s,%s,%s,%s,%s,%s)\n",
  row, test,


printf("Please enter a name\n>");

  for(i=1; i<ROWS; i++) {
      if(issubstring(Course[i],search))  {
                printf("Course %s found!!\nTime 1 is %s\nTime2 is

   if(coursefound==0) printf("No such Course!.\n");



void down_string(char *p)  //turns uppercase letters in a string to
    int i;
        if((p[i]>='A')&&(p[i]<='Z')) p[i]+=32;

char* issubstring(char *str1,char *str2)  //checks if string2 is a
substring of string2
    char tmp1[30],tmp2[30];
    strcpy(tmp1, str1);
    strcpy(tmp2, str2);
    down_string(tmp1);  //turn it to lowercase
    return (strstr(tmp1, tmp2));


char** dynamic_string_array(int ROWS, int SIZE)
  char **array;
  int i;
  array=(char**) malloc(ROWS*sizeof(char));
     array[i]=(char *) malloc(SIZE*sizeof(char));

  return array;

int file_length(FILE *file)
  int lines;
  char dummy[100];


  while( fgets(dummy, 100, file) != NULL)



5.will Hyperlinks work on a CD when created from files stored on Int

relative addressing,(\subdirectory\subdirectory\file.nam) or put them in 
the same folder (file.nam)

mgrady wrote:

> How do you create a hyperlink in (ppt / word) that links to another file and 
> document, when all of the final documents will be stored and accessed from a 
> CD? 

6. pass int* to perl

7. signal processing INT or TERM

8. maximum int value

Return to PERL


Who is online

Users browsing this forum: No registered users and 30 guest