Last active
August 29, 2015 14:23
-
-
Save naimrajib07/8e15a4037edd2ae2bf5f to your computer and use it in GitHub Desktop.
Number Of Bit Count From A Image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @params img_file String | |
# @return number of 0 and 1 | |
# | |
# irb => | |
# => require '/home/naim/Desktop/bit_counter.rb' | |
# => count_bits '/home/naim/Desktop/SAM_1247.jpg' | |
# | |
def count_bits img_file | |
img_file = File.read img_file | |
img_binary_string = img_file.unpack("B*").to_s | |
number_of_ones = img_binary_string.count("1") | |
number_of_zeros = img_binary_string.count("0") | |
puts "found #{number_of_ones} bits set to 1" | |
puts "found #{number_of_zeros} bits set to 0" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment