473,382 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

question binary representations

im doing conversions with two's complement binary numbers and i have some questions.

how can I convert -2047 into a base 2 complement number? I know how to read the binary but there has to be a way to convert it I just don't know how.

I also was trying to figure out how to convert MIPS binary representation for the floating-point number 0.1.


also i solved these and wanted to make sure I was understanding the concepts.
if this is the binary
Expand|Select|Wrap|Line Numbers
  1. 1111 1111 1111 1111 1111 1111 0000 0110
then the number represented is -248

im also doing adding and subtracting
if have two numbers
Expand|Select|Wrap|Line Numbers
  1. 0000 0000 0000 0000 0000 0000 0101 1011
  2. 0000 0000 0000 0000 0000 0000 0000 1101
then the added number in binary would be
Expand|Select|Wrap|Line Numbers
  1. 0000 000 0000 0000 0000 0000 0110 0000
using the same numbers but using the negative of the second one from above, then adding the two
Expand|Select|Wrap|Line Numbers
  1. 0000 0000 0000 0000 0000 0000 0101 1011
  2. 1111 1111 1111 1111 1111 1111 1111 0010
with these two numbers I get
Expand|Select|Wrap|Line Numbers
  1. 0000 0000 0000 0000 0000 0000 0100 1110
Oct 4 '07 #1
5 1637
Banfa
9,065 Expert Mod 8TB
how can I convert -2047 into a base 2 complement number? I know how to read the binary but there has to be a way to convert it I just don't know how.

I also was trying to figure out how to convert MIPS binary representation for the floating-point number 0.1.
Store the number in a variable, the read the bits out of of the variable (if it's an integer) or read the bits from it's memory locations (it it's a float).

Expand|Select|Wrap|Line Numbers
  1. 1111 1111 1111 1111 1111 1111 0000 0110
then the number represented is -248
No it repreents -250

[quote=gdarian216]
im also doing adding and subtracting
if have two numbers
Expand|Select|Wrap|Line Numbers
  1. 0000 0000 0000 0000 0000 0000 0101 1011
  2. 0000 0000 0000 0000 0000 0000 0000 1101
then the added number in binary would be
Expand|Select|Wrap|Line Numbers
  1. 0000 000 0000 0000 0000 0000 0110 0000
[/code]Wrong it would be

Expand|Select|Wrap|Line Numbers
  1. 0000 000 0000 0000 0000 0000 0110 1000


OK the thing to remember is that your computer only uses a binary represenation of any number, usually 2's complement for an integer. To your computer -2047 is just a series of 5 characters, it does not understand or use decimal. What it knows is how to convert it's binary representation into a decimal one when displaying data for the user. The compiler also knows how to convert decimal into binary when it is compiling a program.

As such reading the binary representation of -2047 is trivially easy, assign the value to a variable

Expand|Select|Wrap|Line Numbers
  1. int value = -2047;
  2.  
Then use the shift and bitwise operators to read out a string of binary digits from value.
Oct 4 '07 #2
caN U HELP ME WITH THIS..input an integer containing only 0 and 1 binary number and prints its decimal equivalent..help give me to solve this problem give the codes on this problem..tnx..
Oct 4 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
caN U HELP ME WITH THIS..input an integer containing only 0 and 1 binary number and prints its decimal equivalent..help give me to solve this problem give the codes on this problem..tnx..
Please start your own thread. Hijacking someone else's is rude.
Oct 4 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
how can I convert -2047 into a base 2 complement number? I know how to read the binary but there has to be a way to convert it I just don't know how.
You:
1) Start with 2047
2) reverse 1's and 0's
3) add 1
4) voila!

If you start with -2047 in 2's complement then the abve will covert it back to 2047.
Oct 4 '07 #5
Store the number in a variable, the read the bits out of of the variable (if it's an integer) or read the bits from it's memory locations (it it's a float)
how would the bitwise function help.........i wrote a short program

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  
  7. float i = 0.0;
  8. i = 0.1;
  9. cout << &i;
  10.  
  11. }
and i get 0xbfe392f4-

how would i get the bit value?
Oct 4 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
21
by: nephish | last post by:
i have an interesting project at work going on. here is the challenge. i am using the serial module to read data from a serial input. it comes in as a hex. i need to make it a binary and compare it...
6
by: Arthur J. O'Dwyer | last post by:
As far as I know, C89/C90 did not contain the now-standard offsetof() macro. Did C89 mandate that structs had to have a consistent layout? For example, consider the typical layout of the...
9
by: PengYu.UT | last post by:
Hi, I write the content of a in file "data" (in Sun Machine). Then I read "data" in both SunOS and linux. But the result is different. Do you know how to make it binary data portable. Best...
9
by: Alfonso Morra | last post by:
Hi, I am having some probs with copying memory blocks around (part of a messaging library) and I would like some confirmation to make sure that I'm going about things the right way. I have...
8
by: Darklight | last post by:
how do one convert decimal to binary?
9
by: gamehack | last post by:
Hi all, I've been wondering when I write a structure like: struct { int a; unsigned int b; float c; } mystruct;
37
by: Richard Heathfield | last post by:
candide said: They aren't. An array is an array. An address is a pointer value. These are not the same thing. If you mean that &array and &array are the same, they aren't. They have different...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.