1. Question about 2's complement
Dear all:
I have to compare 2 values which is represented by 2 bytes as 0xffff
and 0x00fe in 2's complement system.
so the difference between them should be -1 - 254 =-255.
but before do such calculation, I have to translate 0xffff as -1.
Is there build-in function in perl for me to use, or should I transfer
it by hand?
below is the method I thought, but it really seems lousy.
my $tmp_value1="ffee";
if (hex $tmp_value1 & 0x8000)
{
my $int=int $tmp_value1;
$int -= 2**16;
$tmp_value1=$int;
}
appreciate your help,
miloody
2. Perl function for negative integers using the 2's complement in hex? - Perl
3. how to do bit complement in perl
hi all, i have a file in which there are 8 byte hex values one followed by another. For example: 2A414364 00001DA9 01A3F9DD 3FFFF661 00EE6670 000011CF 2BC43FD0 3FEB0003 3F7FFF40 I need to check for the last bit in every data and if it being set, then the next data's 24 bits have to be inverted(assuming last bit is d31, starting from d26 to d7 needs to be inverted). For example: 1st data 0x2A414364 has last bit as '0' so the next word can be retained as same.But, 00001DA9(2nd data), the last bit is '1' so the next data 01A3F9DD will have to be printed as 3e5c061d. so, for the upper set of data, the below data needs to be printed. how do i do bit complement in hex using perl. 2a414364 00001da9 3e5c061d 000009a1 3f1199b0 000011cf 143bc010 3feb0003 00800080 regards, bala
5. How does the complement work with transliteration ?
Hello I was wondering how tr/abcd/1234/cs is supposed to work... I intend it to mean- if its anything other than abcd replace with ... I am not sure what the right way is. Without the /c, tr/abcd/1234/s does the expected, replaces each of a b c and d found, with their corresponding replacement characters. But in the /c case I notices that any character that was not one of abcd was replaed with 4, the last character in the REPLACEMENTSTRING 1234. I tried to look at documentation - they have just one example of replacing all that dont fit the search with a space. If any of you have examples of how you use this thing with /c, i'd love to see them. Thanks anita
7. Perl memory usage debugging techniques
I have a search engine that can search in XML documents. The search engine is written in Perl, with some parts in C. It needs inane amounts of memory, so much that the machine often starts to thrash. So now I'm trying to find a way to find out where the memory is used and how to make it use less memory. I have tried som things, but I don't know what else to try. There has got to be a systematic approach which will lead to success somehow, but I haven't found it, yet. I started by writing a batch version that you start from the command line, give it a query, and then it will process that query. By looking at the script, I can see all lexicals that are used and examine their sizes. My findings are as follows: >From the beginning (before query processing starts) to the end (after query processing) the Perl process grows from 19,068 by 71,964 to 91,032 kB. After query processing, the lexicals in use are: parser (1 kB), parsed query (0 kB), low-level interface layer (521 kB), intermediate query representation (521 kB), another intermediate query representation (10 kB), and the query result (4 kB). I didn't count the lexicals that receive command line options, and neither those for parsing the output of "ps -up $$", and also the Log::Log4perl object is missing. All other memory usage happened in lexicals in various methods that have now gone out of scope. The memory could also have been used internally by DB_File or DBM::Deep, the above described run used DBM::Deep. I use those for storing the index created by the search engine. Another possibility, of course, is that the memory is used by the C parts. I used the total_size function from Devel::Size to find the memory usage of the lexicals. Since I don't grok what is going on, the numbers might be misleading. I used the `ps -up $$` construct to find the size of the Perl process. I have also taken the class that I suspected used the most memory, and then changed the constructor and destructor to make an entry in a table for each object created and each object destroyed. Then, whenever an object was created or destroyed, I printed the current statistics on bytes ever allocated and bytes ever freed. This tells me that something like 9 MB of memory was ever freed during the lifetime of the program; this is also not enough to explain the 71 MB used. I intend to use Devel::Symdump to find the symbol table and to sum up its memory usage using Devel::Size, as well. Obviously, these approaches aren't sufficient for finding the problem; can you teach me some technique that could help? I have already learned from a previous posting that Perl does not like to return memory to the system, and often it does not want to reuse memory allocated for another variable. I have no idea how to find unused bits of memory, nor how to find out why Perl didn't reuse other memory, or how to make it reuse more. tia, Kai ----- End forwarded message -----