Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7770579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:26:32+00:00 2026-06-01T16:26:32+00:00

I was just wondering what the code would be to convert a decimal integer

  • 0

I was just wondering what the code would be to convert a decimal integer (entered in by the user) to a 2’s compliment representation in memory.

Example: the user enters 1234 as the decimal. I want to store 04D2 (the binary 2’s complement representation) in AX (since I’m only allowed to use word length strings)

I’m using 80×86 architecture.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:26:33+00:00Added an answer on June 1, 2026 at 4:26 pm

    Converting a string of digits to an integer is mostly fairly simple: you read one digit at a time, convert that to a decimal number (normally by subtracting ‘0’ from it). You take your existing value, multiply it by ten, and add the value of the current digit.

    Dealing with negative numbers adds just a bit more difficulty to that. Most people do it by keeping a flag to indicate the number is negative if it starts with a ‘-‘. Then, when they’ve converted the number, they negate if if that flag is set.

    That does, however, have one problem: converting the most negative number takes some extra work, because (in 2’s complement) the most negative number has a larger magnitude than you can represent as a positive number (without using more bits). For example, 16-bit 2’s complement numbers range from -32768 to +32767, but you need either (at least) 17 bits or an unsigned 16-bit number to represent +32768.

    Edit: Once you’ve converted the decimal digits to an integer, you’ll need to convert the integer to hexadecimal digits to display it in hex. That conversion is a little bit easier. You repeatedly divide by 16 and the remainder becomes the next hexadecimal digit. You’ll normally use a table like “0123456789abcdef” and use that remainder to index into the table to get the digit for display. You repeat the division and using the remainder until your dividend is zero. The one trick is that this produces the digits in reverse order (from least to most significant), so you normally put them into a buffer, starting from the end of the buffer and working your way toward the beginning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering, would the following code arrangement cause any issues when calling mysql_connect, i.e.:
Just wondering what code I would need to do this?
just wondering which approach would be better if both blocks of code would yield
Hey, I'm just wondering what code I could use to auto change the size
Just wondering about this code below... when I turn off my internet connection and
Just wondering is this kind of code recommended to increase performance? void functionCalledLotsofTimes() {
Just wondering if a .NET app can be compiled down to native machine code
Just wondering, if I install a Windows service from 64-bit process (service code embedded
I'm just wondering if there is a best case to write this code: $('#set_duration_30').click(function(event)
I use log4net in just about every code project. I was wondering what other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.