does anyone know a module or something to convert numbers like integer
to binary format ?
for example I want to convert number 7 to 0111 so I can make some
bitwise operations...
Thanks
Jun 1 '06
21 3849
On 2006-06-03, Tim Chase <py*********@ti m.thechases.com > wrote: The fact that they impliment the xor operator is pretty much proof that integers are stored in binary format -- xor is only defined for binary numbers.
Um...let's not use bad logic/proofs for evidencing this...
hasattr(set(), "__xor__")
True
Sets aren't numbers. Perhaps I should have phrased it better:
xor is only defined for numbers if they are represented in
binary. If numbers were represented in something other than
binary, then an xor operation on those numbers wouldn't make
sense.
--
Grant Edwards grante Yow! .. I want to perform
at cranial activities with
visi.com Tuesday Weld!!
Grant Edwards a écrit : On 2006-06-02, Bruno Desthuilliers <bd************ *****@free.quel quepart.fr> wrote:
Grant Edwards a écrit :
On 2006-06-01, ni******@gmail. com <ni******@gmail .com> wrote:
does anyone know a module or something to convert numbers like integer to binary format ?
They _are_ in binary format. Not really.
Yes, really.
No, not really.
Otherwise the bitwise boolean operations you demonstrated wouldn't work as shown.
Ho yes ? >(7).__clas s__ <type 'int'>
>dir((7))
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__' , '__div__', '__divmod__', '__doc__', '__float__', '__floordiv__ ', '__getattribute __', '__getnewargs__ ', '__hash__', '__hex__', '__init__', '__int__', '__invert__', '__long__', '__lshift__ ', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__' , '__repr__', '__rfloordiv_ _', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__']
The fact that they impliment the xor operator is pretty much proof that integers are
.... objects, instance of the int class. Not really what I'd call "binary
format" !-)
Now if you go that way, it's of course true that everything on a
computer ends up in a binary format.... It's true.
stored in binary format -- xor is only defined for binary numbers.
class Prisonner(objec t):
def __xor__(self, other):
return "I'm not a (binary) number, I'm a free man"
The fact that an object implements the xor operator is pretty much proof
that the guy that wrote the class decided to implement the xor operator !-)
Grant, I of course agree that, *for practical means*, one can consider
that Python's integer are "already in binary format" - for a definition
of "binary format" being "you can do bitwise ops on them". But the truth
is that Python integers are objects (in the OO meaning) holding integer
values - not integer values themselves. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David Lawson |
last post by:
I know how to conver a string to an array of strings, but I need to convert an ascii string to an
array of integers (really unsigned chars). Eg,
$str ="ABC";
needs to convert to something like this:
$buf = array(0x41, 0x42, 0x43);
Anyone know how? I haven't been able to find a way.
|
by: Mark Dufour |
last post by:
Hi all,
I need to convert an integer into some binary representation. I found the
following code in the online cookbook (adapted to return a list):
binary = lambda n: n>0 and +binary(n>>1) or
This is sure nice, but I'm wondering why something like this doesn't seem to
be in the standard library, for example by formatting with '%b' % number. I
can't think of a any reason for not doing it this way, as working with binary
|
by: Andrew |
last post by:
Hi I have a question is there a function in C++ to convert an integer into a
Binary number
Thanks in Advance
Cheers
|
by: Mantorok Redgormor |
last post by:
are all integers represented internally as just bit vectors?
-- nethlek
|
by: GS |
last post by:
The stdint.h header definition mentions five integer categories,
1) exact width, eg., int32_t
2) at least as wide as, eg., int_least32_t
3) as fast as possible but at least as wide as, eg., int_fast32_t
4) integer capable of holding a pointer, intptr_t
5) widest integer in the implementation, intmax_t
Is there a valid motivation for having both int_least and int_fast?
| |
by: sathyashrayan |
last post by:
Group,
I have some doubts in the following program.
------------------program---------------------
/*
** Make an ascii binary string into an integer.
*/
#include <string.h>
unsigned int bstr_i(char *cptr)
|
by: shyha |
last post by:
Hello!
Does anybody know what is binary representation of integer datatype
fields written to archlogs on z/OS (OS/390) machines? Is it "Two's
complement", "One's complement", Sign-modulo or whatever?
I would analyze it for myself if someone would provide me with some
binary (hex) representations of some numbers as: 0, 1, -1 and couple
more of your choice.
|
by: David |
last post by:
If I have a loop that has a max value of say 20 why would I not want to
define the loop counter using a BYTE or SHORT as opposed to a INTEGER.
It seems in most books or samples they define fairly small numbers as
INTEGER.
thanks, David
|
by: Default User |
last post by:
Hi,
If I have three 64 bit integers and I want to do this operation on them:
x*y/z
Lets say that what we are multiplying by (y) is offset by what we are
dividing by (z) so that the final answer will fit in a 64-bit integer.
Let me simplify it by using unsigned chars (8 bits):
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |