LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-18-2008, 11:59 AM   #1
prakash.akumalla
Member
 
Registered: Jun 2008
Location: India
Posts: 109

Rep: Reputation: 15
Thumbs up Help me in writing the script


Hi,

I have written a script which converts a give hexdecimal value to binary value in perl. But now, the problem is I should read every bit of it ( if its 10101010, i should read the value in each position and if the value in that position is 1 i should print a string and should exit if its 0).

I have written a hash table for positions 0,1,2..7 . It should check if the 0th position is either 1 or 0. If its 1 then it should print the key in the hash table for the value 0. If its 0 then it should exit.

Please help me in doing so.

Thanks,
Prakash.
 
Old 12-18-2008, 01:15 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
Posting the actual code could get you meaningful responses.
 
Old 12-18-2008, 02:01 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,933

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by prakash.akumalla View Post
Hi,

I have written a script which converts a give hexdecimal value to binary value in perl. But now, the problem is I should read every bit of it ( if its 10101010, i should read the value in each position and if the value in that position is 1 i should print a string and should exit if its 0).

I have written a hash table for positions 0,1,2..7 . It should check if the 0th position is either 1 or 0. If its 1 then it should print the key in the hash table for the value 0. If its 0 then it should exit.

Please help me in doing so.

Thanks,
Prakash.
If you've already done it, why do you need help? You say you've written a script which does what you want, wrote the hash table, etc.

Or are you looking for someone to write this for you? Post what you've written so far, and what error(s) you've found, and we can try to help you. I doubt, though, anyone is going to write your programs for you for free....
 
Old 12-19-2008, 12:15 AM   #4
prakash.akumalla
Member
 
Registered: Jun 2008
Location: India
Posts: 109

Original Poster
Rep: Reputation: 15
Hi,

What i need is to split a binary number (10101011) to separate entries into an array.

now $x = 10101011
it should be @x = (1,0,1,0,1,0,1,1)

How can we convert this?

Thanks,
Prakash.
 
Old 12-19-2008, 03:03 AM   #5
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,036

Rep: Reputation: 96
As you are using Perl.

Have a look at split
 
Old 12-19-2008, 03:41 AM   #6
prakash.akumalla
Member
 
Registered: Jun 2008
Location: India
Posts: 109

Original Poster
Rep: Reputation: 15
Hi,

Thanks for your reply. I have tried it but could not get the required result.

I have tried by giving,

$x =~ s/undef/,/g;

But it did not work.

let me say my complete requirement once.

Input to the file will be hexadecimal of 2 digits (A1 or B1).

It should be converted to binary and next for every 1 in the string we should generate a message which is predefined for that position.

If the value in that position is 1 a flag should be set and a string should be displayed.

Please assist me in doing so.

Thanks,
Prakash.
 
Old 12-19-2008, 02:25 PM   #7
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,036

Rep: Reputation: 96
Code:
$x='0101011001';
@y=split(//, $x);
 
Old 12-19-2008, 02:49 PM   #8
lumak
Member
 
Registered: Aug 2008
Location: Phoenix
Distribution: Arch
Posts: 799
Blog Entries: 32

Rep: Reputation: 111Reputation: 111
There shouldn't be any reason to split the binary number in an array. All you have to do is OR the value to check it. In fact! chances are there is already a sutible library or functions for handling this. The concept is called a bit vector... You store an integer which can then have 'OR' or 'AND' operators placed on them against another integer to see if the value is 1 or 0.

10110 = 22
check second position
22 & 2 = 2

Code:
 10110
&00010
------
 00010

20 & 2 = 0
 10100
&00010
------
 00000
a bit vector library and documentation would be more helpful.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help: Writing a Script ktg Programming 5 05-06-2008 08:18 AM
Need help writing script DJ 2501 Linux - Software 1 07-22-2007 07:33 PM
Need help writing script Rustylinux SUSE / openSUSE 1 12-05-2006 11:05 AM
Need help writing a script wswartz Linux - Software 3 04-28-2004 04:35 PM
writing a Script spanky5125 Linux - Security 5 01-08-2002 10:22 AM


All times are GMT -5. The time now is 08:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration