Python Forum
Converting an 8-bit binary to decimal WITHOUT the shortcuts
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting an 8-bit binary to decimal WITHOUT the shortcuts
#1
Hey everyone, I am trying to self-teach myself in python and I was wondering. Is there a way to convert an 8-bit binary to decimal without using the shortcuts? I don't have any code for this yet because I wouldn't even know where to start beside get the input via possibly strings or integers. I'm using python 3.x also.

Any help would be awesome.
Reply
#2
Have you tried converting them manually on paper? If not, this is a good place to start.
https://www.wikihow.com/Convert-from-Binary-to-Decimal

Having understood that, you can try convert that into a python.

If not

>>> int(bin(8)[2:], 2)
8
Reply
#3
Of course there is. It probably run slower then builtin.

Make a string.
Loop through with enumerate.
add bit shift value against length of string - enumerate + 1 to total
99 percent of computer problems exists between chair and keyboard.
Reply
#4
I understand how to convert them on paper, I'm just a bit confused on how to convert the string into each binary number. Also, I'm trying to learn everything with less shortcuts. If I can do it without shortcuts I can easily explain it with shortcuts later down the road
Reply
#5
(Dec-01-2017, 07:24 AM)EIA Wrote: I'm just a bit confused on how to convert the string into each binary number.

you can iterate over a string or convert it to list with built-in function and iterate over that list
Reply
#6
Try following these simple steps:
  1. Write out steps for doing it manually
  2. Try writing code that does the same thing
  3. Post here if you run into a specific problem
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help with infinite loop & making hotkeys/shortcuts Graxum 1 1,158 Aug-22-2022, 02:57 AM
Last Post: deanhystad
  Creating Shortcuts with python Oshadha 2 1,834 Jun-23-2022, 08:07 AM
Last Post: Oshadha
  Converting an RGBA image to Grayscale and Binary Joni_Engr 3 4,626 Aug-23-2021, 11:54 AM
Last Post: Pedroski55
  Binary to decimal script ThorOdinson12521 1 1,861 May-19-2020, 04:22 PM
Last Post: ThorOdinson12521
  hex file to binary or pcap to binary baran01 1 5,685 Dec-11-2019, 10:19 PM
Last Post: Larz60+
  Converting str to binary ebolisa 1 2,021 Jun-17-2019, 11:50 PM
Last Post: scidam
  IDLE keyboard shortcuts tam 2 2,870 May-15-2019, 06:34 AM
Last Post: tam
  testing for Decimal w/o importing decimal every time Skaperen 7 4,432 May-06-2019, 10:23 PM
Last Post: Skaperen
  converting binary b'0x31303032\n' to "1002" string amygdalas 2 2,635 Nov-07-2018, 03:50 AM
Last Post: amygdalas
  Converting Decimal to Binary emerger 1 2,794 Feb-27-2018, 08:06 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020