Showing the binary representation of an integer.
I see a lot of people asking about getting the binary (string) representation of a number in various languages. Changing the base for a number is not that tricky, and getting the binary representation of the a number is really easy.All this uses is a simple bit shift (">>" right shift), and the the AND ("&") bit operator. These operators are pretty common. Here is a simple Python function to convert the number.
>>> def tobinary(n,size=32): ... return ''.join([str((n >> i) & 1) for i in range(size -1, -1, -1)]) ... >>> tobinary(0xF, 8) '00001111' >>> tobinary(5, 8) '00000101' >>> tobinary(4, 8) '00000100' >>>
Yup, that's all there is to it.
Very Important
I was going to upgrade this server, but then I realized I don't want to. It's a PIII 450mhz machine, with 256MB of memory. There is an 8GB Western Digital drive as the primary drive, and then a 40GB Western Digital driver for extra storage.I bought it from Percy's (when they custom built computers), a while back. It rocks the house and rules the internet.
Thanks for reading my blog.
Software
All software is released under the LGPL, unless specifically noted otherwise.
Scheck
scheck
I posted the source to my server monitoring program. It's very simple,
but it worked for me at 2 of my past jobs. It's free and released under
the LGPL.
NTimer
NTimerLib, NTimerGUI, NTimerCL
I posted my free time tracking tool, called NTimer ( uses
NTimerLib ), and all of the source code. It's
written entirely in C# and will build and run using the .NET 2.0
framework and Mono. You can find it right here.
The current version is 0.1 and is released under the LGPL.


