[ Log On ]
  • Home
  • Tst
  • Cha
  • Enc
  • Code
  • IP
  • Fun
  • Sub
  • DigF
  • Cis
  • Com
  • Db
  • About
  • Netsim

Integer representation

 

Back With hexadecimal we take four bits at a time and convert them into a hexadecimal value, and normally we show that we are using hexadecimal with leader characters. The table we use is:

Val	Hex		Val	Hex
0000	0		1000	8
0001	1		1001	9
0010	2		1010	A
0011	3		1011	B
0100	4		1100	C
0101	5		1101	D
0110	6		1110	E
0111	7		1111	F

An example is 42 which is “0010 1011”, and where we can represent this with 0x2B. With octal we take three bits at a time, and represent them with a value from 0 to 7.

Bit masking

Enter binary values (the page should detect binary or decimal values):

Bit value:

Try an example

  • For "42". Calc
  • For "65" gives 0x41 and 'A'. Calc
  • For "97" gives 0x61'a'. Calc

Coding

The following shifts a binary value to the left and right by one bit position:

import sys

val1=43

if (len(sys.argv)>1):
        val1=int(sys.argv[1])

print "Dec:\t",val1
print "Bin:\t",bin(val1)
print "Hex:\t",hex(val1)
print "Oct:\t",oct(val1)
print "Char:\t",chr(val1)

Sample run

A sample run is:

Dec:    43
Bin:    0b101011
Hex:    0x2b
Oct:    053
Char:   +