473,408 Members | 2,888 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,408 software developers and data experts.

Binary number manipulation

Hello All!

I am very new to python so I am working on some ass-umptions which may be incorrect (please forgive me).

I am working on a problem that requires me to take 2 decimal integers, each of which represents half of a word. I need to slap these things together and get out another decimal integer.
A couple of questions:
1. Is there a way to typecast a variable as a binary?
2. If 1 is no, does that mean that I need to do all the manipulation in some icky string format and then go back?

I do see the bit-wise operations available and this looks like I need to simply perform these on my integers? Can it really be that simple?

Thanks,
Matt
Jul 18 '05 #1
1 2598
Matthew A. Berglund wrote:
I am working on a problem that requires me to take 2 decimal integers, each
of which represents half of a word. I need to slap these things together
and get out another decimal integer. [...] I do see the bit-wise operations available and this looks like I need to
simply perform these on my integers? Can it really be that simple?


Probably. Consider the following (typed at the interactive prompt):
a=0x1234
b=0xabcd
i=a<<16 | b
print i 305441741 print hex(i)

0x1234abcd

This example assumes that both words are 16 bits.
There are some signed/unsinged issues, be warned.
--Irmen

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ferran Foz | last post by:
Hello, I'm using ADODB.Stream to open a binary file on the server and write it down to the browser using Response.BinaryWrite. It's working fine, but i need to make some changes to the binary...
10
by: J. Campbell | last post by:
OK...I'm in the process of learning C++. In my old (non-portable) programming days, I made use of binary files a lot...not worrying about endian issues. I'm starting to understand why C++ makes...
2
by: Mariusz Sakowski | last post by:
I'm writing class which will be able to store large numbers (my ambition is to make it able to operand on thousands of bits) and perform various operations on it (similiar to those available with...
1
by: rusttree | last post by:
I'm working on a program that manipulates bmp files. I know the offset location of each piece of relevent data within the bmp file. For example, I know the 18th through 21st byte is an integer...
8
by: vendredi5h | last post by:
Hello all, I'd like to split a 64-bits word (hold as a floating point number) into two 32-bits words (hold as integers). Bitwise operators are working on Integers, not on floating point. ...
6
by: LaVic | last post by:
Hello Everyone, I am trying to add two binary numbers in the form of two arrays. The code that i have been using compiles, but it does not give me the results i would expect. The problem that i...
3
by: nguser3552 | last post by:
Hello Everyone, I have a problem I can't surmount, anything is gravy at this point. I need to be able to read any type of file .ext (mov,mpeg,mp3,etc) in binary format. I can do this in C, but ...
3
by: tfeller | last post by:
I would like to drop the leading 0x on a binary value so I can do a bitwise operation. Here is simplified code: select right(0x88186000,8) I expected to get back 88186000, this was not the...
7
by: azrael | last post by:
Hy folks, I googled, and searched, and can not bealive that I have not found a built in way to convert the easy and elegant python way a function to easily convert simple ascii data to binary...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.