• 0

decimal to binary


Question

can anyone show me how to convert from decimal numbers (ie. -12, 8, 14 -3 etc...) to binary numbers (ie. 00001010) in ones complement and two's complement...? and how to convert between ones complement and two's complement with positive and negative numbers...? thanks in advanced.....^^

or is there sites that show how to do it...? thanks........

Link to comment
https://www.neowin.net/forum/topic/58452-decimal-to-binary/
Share on other sites

6 answers to this question

Recommended Posts

  • 0

i use a table wen i convert decimal to binary

binary's base is always 2

and u go backwards

lets start with 6 powers

2^6 2^5 2^4 2^3 2^2 2^1 2^0

64 32 16 8 4 2 1

lets take for example a decimal number 20

u see through the table which number goes into 20, well obviously 16 does

so there fore u have one thing that went into it

so u add a 1

then ur left with a remainder of 4 now u see which one it can go into it

the next one is perfect so u add a 1

now u have no remainders but u gotta fill up the spaces so u just add two 0's

there fore the binary number for 20 is 1100

im not a good explainer sorry..

Link to comment
https://www.neowin.net/forum/topic/58452-decimal-to-binary/#findComment-588991
Share on other sites

  • 0

:no: :wacko: :blink:

sorry but i don't get your explanation.... :blush:

can somebody explain it to me or suggest a site to me...?

other than converting to binary, i need to know more about ones and two's complement....

and also adding and subtracting binary numbers.........thanks in advanced...

Link to comment
https://www.neowin.net/forum/topic/58452-decimal-to-binary/#findComment-589014
Share on other sites

  • 0

Decimal to binary

First, know that just like each digit in a decimal number represents a power of ten (so the 2 in 1234 represents 2 x 10^2), each digit in a binary number represents a power of two. 1, 2, 4, 8, 16, 32, 64, 128, 256, etc. 101 (base 2) = (1 x 2^2) + (0 x 2^1) + (1 x 2^0).

So. Break the decimal number into it's power of two components. Then, for each bit, check if the corresponding power of two is present. If it is, the bit is a one, otherwise it's a zero.

For example:

42 = 32 + 8 + 2

42 = 2^5 + 2^3 + 2^1

42 = (1 x 2^5) + (0 x 2^4) + (1 x 2^3) + (0 x 2^2) + (1 x 2^1) + (0 x 2^0)

42 = 101010 (base 2)

29 = 16 + 8 + 4 + 1

29 = 2^4 + 2^3 + 2^2 + 2^0

29 = (1 x 2^4) + (1 x 2^3) + (1 x 2^2) + (0 x 2^1) + (1 x 2^0)

29 = 11101 (base 2)

If your wondering how to do the first step, it's easy. Just keep subtracting the highest power of two you can until you reach zero. Like for 42 (the first example):

42 - 32 = 10

10 - 8 = 2

2 - 2 = 0

So the powers of two are 32, 8 and 2.

PS: I'm tired, I'll answer the rest of your question later :p

PS2: By the way Winston, binary for 20 is not 1100, it's actually 10100. :blink:

Link to comment
https://www.neowin.net/forum/topic/58452-decimal-to-binary/#findComment-589246
Share on other sites

  • 0

The Number -4:

(0100) = 4

(1100) = -4

Complement all bits and add 1, or complement every bit (going from right to left) after the first 1.

In 2's complement the most significant bit represents a negative number. in this case -8, all the other bits are positive numbers.

in 1's complement you simply complement all bits.

Link to comment
https://www.neowin.net/forum/topic/58452-decimal-to-binary/#findComment-589464
Share on other sites

  • 0

Now after looking at the relpies answering how to convert from decimal to binary, I realized how impractical that is for programming. What happens if you want to convert a number like 781,456,945? Are you going to use the powers of 2? No. There is a really cool way of doing it that involves a simple for loop and modulus (% operator). The modulus of 2 numbers is the remainder after division. So 5%2=1 because 5/2 = 2 remainder 1. If you already knew what modulus is then great! Anyway, if you want to convert 42 to binary do the following:

Starting with 42%2:

42/2 = 21 R 0

21/2 = 10 R 1

10/2 = 5 R 0

5/2 = 2 R 1

2/2 = 1 R 0

1/2 = 0 R 1

Reading the remainders (moduluses) from the bottom you get 101010. There you go!

If you want to know how to convert to decimal from binary, I know another really simple way involving synthetic division. Just contact me in anyway you want to learn how.

Edited by jl7c2
Link to comment
https://www.neowin.net/forum/topic/58452-decimal-to-binary/#findComment-593787
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • They've been focusing on security and quality? Could have fooled me. Their own paying customers literally just got breached because they failed to push SharePoint updates downstream to on prem servers operating outside of their "365" ecosystem.
    • The animosity is unnecessary, when I opened the page I only saw one response which never mentioned your other steps, and when I hit reply it jumped straight to the bottom and again, I saw no other responses.  I was simply agreeing with the first comment that said yes, you should be fine if you erase its current operating system. Using another PC, or the copy of Windows that comes on that PC (former option is more trustworthy), download and run the Windows Media Creation tool.  It will walk you thru the process of downloading Windows and writing it to a USB stick.  It will even ask you at one point whether you're reinstalling it to the current machine or installing it on another machine. Then just boot the PC in question from that USB stick.  Usually spamming Esc, Del, F-8, F-9, F-10, F-11, F-12 or F-2 immediately after power on will bring up a boot menu, it varies by manufacturer.  If Windows starts booting you either missed your window or hit the wrong key. Follow the on-screen instructions.  When it gets to the disk formatting part I usually just delete all the partitions on the destination drive, then select the unpartitioned space as my destination.  The Windows installer will then automatically partition the drive as needed. Be prepared to download drivers from the PC manufacturer's website, they may not come bundled with Windows and you may not be able to use things like WiFi or ethernet until you have them.  They "might" work straight away, but they also might not.  Better to be prepared with a spare PC and a USB stick to transfer them over.
    • Wise Disk Cleaner 11.2.5 by Razvan Serea Wise Disk Cleaner is a free disk utility designed to help you keep your disk clean by deleting any unnecessary files. Usually, these unnecessary, or junk files appear as a result of program's incomplete uninstalls, or Temporary Internet Files. It is best if these files are wiped out from time to time, since they may, at some point, use a considerable amount of space on your drives. Wise Disk Cleaner, with its intuitive and easy to use interface, helps you quickly wipe out all the junk files. Using the program is indeed easy. It also works fast when both scanning for files and deleting files. The new Wise Disk Cleaner has more advantages: improved performance, better interface and scans/cleans more thoroughly. Wise Disk Cleaner Free provides lifetime free update service and Unlimited Free technical support. The first Slimming System software Wise Disk Cleaner is the first system slimming tool, which will help you to remove Windows useless files that you don't need, such as Korean IME, Windows Sample music, videos, pictures, Installers and Uninstallers of Updates Patches etc. Wise Disk Cleaner 11.2.5 Build 845 changelog: Added cleaning rules for Legacy Games Launcher, Letasoft Sound Booster, Macrium Reflect, MagicLine4NX, MAGIX Photostory, MakeHuman, Max Recorder, Maxprog iCash, Lexware, LG PC Suite, Lightworks, LINE, Listary, and LockHunter. Improved cleaning rules for Xunlei, PowerToys, Meitu, OneDrive, and Tencent Video. For security reasons, users can no longer delete the latest system restore point in the Restore Center. Enhanced System Slimming. Fixed minor bugs from the previous version. Download: Wise Disk Cleaner 11.2.5 | 6.9 MB (Freeware) Download: Portable Wise Disk Cleaner 11.2.5 | 7.3 MB View: Wise Disk Cleaner Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • I keep getting ignored when I ask what you guys mean by nuke it. I described the steps and I keep getting the same generic instructions. Can you look at what I have posted multiple times already and validate what I have described? You can't assume everyone has your level of expertise and can interpret your nuking advice. After this many posts in this thread, I don't think we need the same generic advice about just nuke it and reinstall. It's already been said. So can you please outline the specifics? Made in Ukraine? Are you sure?
  • Recent Achievements

    • One Year In
      armandointerior640 earned a badge
      One Year In
    • One Month Later
      armandointerior640 earned a badge
      One Month Later
    • One Month Later
      Itbob513626 earned a badge
      One Month Later
    • Week One Done
      Itbob513626 earned a badge
      Week One Done
    • Rookie
      EdwardFranciscoVilla went up a rank
      Rookie
  • Popular Contributors

    1. 1
      +primortal
      615
    2. 2
      ATLien_0
      236
    3. 3
      Xenon
      155
    4. 4
      +FloatingFatMan
      120
    5. 5
      Michael Scrip
      115
  • Tell a friend

    Love Neowin? Tell a friend!