how to do bit complement in perl

I

IJALAB

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
 
S

smallpond

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top