Sponsored Content
Full Discussion: Print count of unique values
Top Forums Shell Programming and Scripting Print count of unique values Post 302980300 by H squared on Friday 26th of August 2016 01:19:15 AM
Old 08-26-2016
Print count of unique values

Hello experts,

I am converting a number into its binary output as :

Code:
 read n
echo "obase=2;$n" | bc

I wish to count the maximum continuous occurrences of the digit 1.

Code:
 
 Example : 
  
 1. The binary equivalent of 5 = 101. Hence the output must be 1.
 2. The binary equivalent of 6 = 110. Hence the output must be 2.
 3. The binary equivalent of 9 = 1001. Hence the output must be 1.
 4. The binary equivalent of 13 = 1101. Hence the output must be 2

Could you please help.

Thanks,
Haider
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

2. Shell Programming and Scripting

How to count Unique Values from a file.

Hi I have the following info in a file - <Cell id="25D"/> <Cell id="26A"/> <Cell id="26B"/> <Cell id="26C"/> <Cell id="27A"/> <Cell id="27B"/> <Cell id="27C"/> <Cell id="28A"/> I would like to know how would you go about counting all... (4 Replies)
Discussion started by: Prega
4 Replies

3. Shell Programming and Scripting

List unique values and count instances in .csv file

I need to take the second column of a .csv file and count the number of instances of each unique value in that same second column. I'd like the output to be value,count sorted by most instances. Thanks for any guidance! Data example: 317476,317756,0 816063,318861,0 313123,319091,0... (4 Replies)
Discussion started by: batcho
4 Replies

4. Shell Programming and Scripting

Find and count unique date values in a file based on position

Hello, I need some sort of way to extract every date contained in a file, and count how many of those dates there are. Here are the specifics: The date format I'm looking for is mm/dd/yyyy I only need to look after line 45 in the file (that's where the data begins) The columns of... (2 Replies)
Discussion started by: ronan1219
2 Replies

5. Shell Programming and Scripting

Looping through entire directory and count unique values

Hello, I`m a complete newbie to coding, please help with this problem. I have multiple files in a directory, I have to loop through the contents of each file and extract number of unique isoforms in that file. Each file is tab delimited and only the line with the first parent (column 3)... (1 Reply)
Discussion started by: ritakadm
1 Replies

6. Shell Programming and Scripting

Count frequency of unique values in specific column

Hi, I have tab-deliminated data similar to the following: dot is-big 2 dot is-round 3 dot is-gray 4 cat is-big 3 hot in-summer 5 I want to count the frequency of each individual "unique" value in the 1st column. Thus, the desired output would be as follows: dot 3 cat 1 hot 1 is... (5 Replies)
Discussion started by: owwow14
5 Replies

7. Shell Programming and Scripting

Count Unique values from multiple lists of files

Looking for a little help here. I have 1000's of text files within a multiple folders. YYYY/ /MM /1000's Files Eg. 2014/01/1000 files 2014/02/1237 files 2014/03/1400 files There are folders for each year and each month, and within each monthly folder there are... (4 Replies)
Discussion started by: whegra
4 Replies

8. UNIX for Beginners Questions & Answers

Print lines based upon unique values in Nth field

For some reason I am having difficulty performing what should be a fairly easy task. I would like to print lines of a file that have a unique value in the first field. For example, I have a large data-set with the following excerpt: PS003,001 MZMWR/ L-DWD// * PS003,001... (4 Replies)
Discussion started by: jvoot
4 Replies

9. Shell Programming and Scripting

Count number of unique values in each column of array

What is an efficient way of counting the number of unique values in a 400 column by 1000 row array and outputting the counts per column, assuming the unique values in the array are: A, B, C, D In other words the output should look like: Value COL1 COL2 COL3 A 50 51 52... (16 Replies)
Discussion started by: Geneanalyst
16 Replies

10. Shell Programming and Scripting

Issue using awk to print min values for unique ids

I am using the following script to search for and print minimum values for each individual Fields (3-14) for each unique id (Field 1). But when the field contains a "-99.99" ( I am ignoring "-99.99") and when the minimum value is the first line of a new id (Field 1), the output does not print Field... (13 Replies)
Discussion started by: ncwxpanther
13 Replies
BINDEC(3)								 1								 BINDEC(3)

bindec - Binary to decimal

SYNOPSIS
number bindec (string $binary_string) DESCRIPTION
Returns the decimal equivalent of the binary number represented by the $binary_string argument. bindec(3) converts a binary number to an integer or, if needed for size reasons, float. bindec(3) interprets all $binary_string values as unsigned integers. This is because bindec(3) sees the most significant bit as another order of magnitude rather than as the sign bit. PARAMETERS
o $binary_string - The binary string to convert Warning The parameter must be a string. Using other data types will produce unexpected results. RETURN VALUES
The decimal value of $binary_string EXAMPLES
Example #1 bindec(3) example <?php echo bindec('110011') . " "; echo bindec('000110011') . " "; echo bindec('111'); ?> The above example will output: 51 51 7 Example #2 bindec(3) interprets input as unsigned integers <?php /* * The lesson from this example is in the output * rather than the PHP code itself. */ $magnitude_lower = pow(2, (PHP_INT_SIZE * 8) - 2); p($magnitude_lower - 1); p($magnitude_lower, 'See the rollover? Watch it next time around...'); p(PHP_INT_MAX, 'PHP_INT_MAX'); p(~PHP_INT_MAX, 'interpreted to be one more than PHP_INT_MAX'); if (PHP_INT_SIZE == 4) { $note = 'interpreted to be the largest unsigned integer'; } else { $note = 'interpreted to be the largest unsigned integer (18446744073709551615) but skewed by float precision'; } p(-1, $note); function p($input, $note = '') { echo "input: $input "; $format = '%0' . (PHP_INT_SIZE * 8) . 'b'; $bin = sprintf($format, $input); echo "binary: $bin "; ini_set('precision', 20); // For readability on 64 bit boxes. $dec = bindec($bin); echo 'bindec(): ' . $dec . " "; if ($note) { echo "NOTE: $note "; } echo " "; } ?> Output of the above example on 32 bit machines: input: 1073741823 binary: 00111111111111111111111111111111 bindec(): 1073741823 input: 1073741824 binary: 01000000000000000000000000000000 bindec(): 1073741824 NOTE: See the rollover? Watch it next time around... input: 2147483647 binary: 01111111111111111111111111111111 bindec(): 2147483647 NOTE: PHP_INT_MAX input: -2147483648 binary: 10000000000000000000000000000000 bindec(): 2147483648 NOTE: interpreted to be one more than PHP_INT_MAX input: -1 binary: 11111111111111111111111111111111 bindec(): 4294967295 NOTE: interpreted to be the largest unsigned integer Output of the above example on 64 bit machines: input: 4611686018427387903 binary: 0011111111111111111111111111111111111111111111111111111111111111 bindec(): 4611686018427387903 input: 4611686018427387904 binary: 0100000000000000000000000000000000000000000000000000000000000000 bindec(): 4611686018427387904 NOTE: See the rollover? Watch it next time around... input: 9223372036854775807 binary: 0111111111111111111111111111111111111111111111111111111111111111 bindec(): 9223372036854775807 NOTE: PHP_INT_MAX input: -9223372036854775808 binary: 1000000000000000000000000000000000000000000000000000000000000000 bindec(): 9223372036854775808 NOTE: interpreted to be one more than PHP_INT_MAX input: -1 binary: 1111111111111111111111111111111111111111111111111111111111111111 bindec(): 18446744073709551616 NOTE: interpreted to be the largest unsigned integer (18446744073709551615) but skewed by float precision NOTES
Note The function can convert numbers that are too large to fit into the platforms integer type, larger values are returned as float in that case. SEE ALSO
decbin(3), octdec(3), hexdec(3), base_convert(3). PHP Documentation Group BINDEC(3)
All times are GMT -4. The time now is 08:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy