You are given a positive integer $N.
Write a script to find out if the binary representation of the given integer is Palindrome. Print 1 if it is otherwise 0.
#!/usr/bin/env tclsh
if {$argc >= 1} {
set number [lindex $argv 0]
} elseif {$argc == 0} {
puts "Please input a number"
exit
}
if {$number < 0} {
puts "0"
} elseif {$number >= 0} {
set result [format %b $number]
set res [string reverse $result]
if {[string compare $result $res]==0} {
puts "1"
} else {
puts "0"
}
}
沒有留言:
張貼留言