Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to do bit complement in perl

Reply
Thread Tools

how to do bit complement in perl

 
 
IJALAB
Guest
Posts: n/a
 
      01-09-2008
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
 
Reply With Quote
 
 
 
 
smallpond
Guest
Posts: n/a
 
      01-09-2008
On Jan 9, 2:20 pm, IJALAB <(E-Mail Removed)> wrote:
> 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


Test low bit
perl -e 'print hex( "2A414364") & 1 ? "odd" : "even";'
even
perl -e 'print hex( "00001DA9") & 1 ? "odd" : "even";'
odd

Complement whole word
perl -e 'printf "%08x",~hex( "00001DA9");'
ffffe256

XOR with mask
perl -e 'printf "%08x", 0x00ffff00 ^ hex( "01A3F9DD");'
015c06dd


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
2's complement vs. 1's complement vs. ... Roberto Waltman C Programming 4 06-13-2011 11:26 PM
1's complement and 2's complement sarathy C++ 22 08-02-2006 05:53 PM
1's complement and 2's complement sarathy C Programming 20 08-02-2006 05:53 PM
sign magnitude, ones complement, two's complement Mantorok Redgormor C Programming 8 10-07-2003 11:52 PM



Advertisments