Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

base-conversion

Converting binary to decimal integer output

August 10, 2023 by Tarik

You can use int and set the base to 2 (for binary): >>> binary = raw_input(‘enter a number: ‘) enter a number: 11001 >>> int(binary, 2) 25 >>> However, if you cannot use int like that, then you could always do this: binary = raw_input(‘enter a number: ‘) decimal = 0 for digit in binary: … Read more

Categories python Tags base-conversion, binary, integer, python, python-2.7 Leave a comment

Converting an integer to a hexadecimal string in Ruby

October 13, 2022 by Tarik

You can give to_s a base other than 10: 10.to_s(16) #=> “a” Note that in ruby 2.4 FixNum and BigNum were unified in the Integer class. If you are using an older ruby check the documentation of FixNum#to_s and BigNum#to_s

Categories ruby Tags base-conversion, hex, ruby Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa