Get the places of binary digits in the korn shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the places of binary digits in the korn shell script
# 1  
Old 12-03-2010
Get the places of binary digits in the korn shell script

TO THE ALMIGHTY FORUM ,
though i have already posted the same question on hex to binary thread , i am posting here also for other beginners who may benefit from this thread...

I have a 32 bit binary containing a series of 1' and 0's , and i am stuck in between the script trying to get the value 1' and 0's into the respective variables , the variables range from b1 to b32 ...

so here goes my question

binary = 101010101010101010101010101010101010101010101 ( 32 bits of 1 and 0's)

looking at the above number .. i am trying to get the values of the 1' s and 0's into their respective place variables ... in the above case the result of the query should assign the values of 1 and 0's to their variables , so i can address those variables in the rest of the script

my rest of the script looks like this

if $b1 = 1 then raise the flag
else if $b1=0 then do not raise the flag

if $b2 = 1 then raise the flag
else if $b2 = 0 then do not raise the flag

if $b3= 1 then raise the flag
else if $b3=0 then do not raise the flag

so on fo the 32 variables.................

Your suggestions ..comments and help is appreciated
# 2  
Old 12-03-2010
And store them into an array ?
bash code:
  1. Binary="10101010101010101010101010101010"
  2. for ((i=0; i<${#Binary}; i++)); do
  3.    A&#91;$i]=${Binary:$i:1}
  4. done
  5. # to display the values
  6. for i in ${!A[@]} do
  7.    echo "$i ${A[$i]}"
  8. done
# 3  
Old 12-03-2010
Quote:
though i have already posted the same question on hex to binary thread , i am posting here also for other beginners who may benefit from this thread...
Venu, please do not create duplicate threads.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed / awk script to delete the two digits from first 3 digits

Hi All , I am having an input file as stated below 5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011 611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011 3486... (4 Replies)
Discussion started by: kshitij
4 Replies

2. Programming

DB2 convert digits to binary format

Dear Team We use DB2 v10.5 and using DBArtisan tool Can someone please guide how to convert digits to binary numbers using db2 feature. Ex> for number 9 , binary should be 1001 ( 8+1) Any help appreciated. Thanks (2 Replies)
Discussion started by: Perlbaby
2 Replies

3. Shell Programming and Scripting

How to define two digits variable in shell script?

Dear Shell script Experts, I am working on shell script which is defined here, qsub_seq.csh . The purpose of this script is to read few input files (with defined starting index and last index) and make processing faster over server. For some task, I had 1064 of input files, so I wrote another... (8 Replies)
Discussion started by: emily
8 Replies

4. Shell Programming and Scripting

Printing with decimal places from last 4 digits

I have input file like below, 201424|9999|OSS|622010|RGT|00378228764 201424|8888|OM|587079|RGT|00284329675 201424|7777|OM|587076|RGT|00128671024 201424|6666|OM|581528|RGT|00113552084 Output should be like below, should add decimal (.) from last 4 digits. ... (2 Replies)
Discussion started by: vinothsekark
2 Replies

5. Shell Programming and Scripting

summing the digits of a binary nuMBER

please help me write a perl program to find the difference of 1 and zeros of a 6 digit binary number. eg If input is 111100 expected output +2 if input is 000011 expected output -2 input is 000111 expected output 0 (2 Replies)
Discussion started by: dll_fpga
2 Replies

6. Homework & Coursework Questions

Korn Shell Script

1. The problem statement, all variables and given/known data: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. 2. Relevant commands, code,... (3 Replies)
Discussion started by: burm
3 Replies

7. Shell Programming and Scripting

Korn Shell Script

I have to solve some exercises in Korn Shell, but i'm having some problems. For example: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. I... (3 Replies)
Discussion started by: burm
3 Replies

8. AIX

Help with Korn Shell script

I have this Korn shell script that runs via a cron entry. It runs in a loop "watching" a specific file system for files with a certain name. The file system that it is watching is an upload file system for an FTP server. When files that are the correct name come in, it takes the extension of the... (1 Reply)
Discussion started by: heprox
1 Replies

9. UNIX Desktop Questions & Answers

korn shell script

hi all i am writing the korn shell script. i have a SQL script which gives me the folowing output DSA.WLG.20050713211544.20051025.20050713211544 28991 1130198400 DSA.WLG.20050713211544.20051025.20050713211544 25881 1130198400 DSA.WLG.20050711210100.20051025.20050711210100 25881 ... (3 Replies)
Discussion started by: pavan_test
3 Replies

10. UNIX for Dummies Questions & Answers

korn shell script

hello., i have 2 files.. 1 file is in this folder /home/test/ssk/DSA.WLG.20050713211544.20050710.20050713211544 (this part) other file is in this folder /home/kk/dev/DSA.WLG.20050711210100.20050710.20050711210100 ... (1 Reply)
Discussion started by: pavan_test
1 Replies
Login or Register to Ask a Question