I would like to convert whole integers from decimal to binary in ArcGIS using the field calculator.

I am looking for the equivalent of DEC2BIN excel command.

All values are 255 or below so 8 bit is fine.

It must have 0 padding to the left. So for example 4 must be 00000100.

I can do it by exporting the attribute table to Excel and using the Dec2Bin command in Excel and rejoin the data but I would like it in a model so want to use the field calculator.

Dec2Bin (Value, 8) works in Excel.

Attached is how I would like it to look when complete.

enter image description here

So basically change the value to and 8 digit binary value stored as a text field with leading 0s so all field have 8 values.

I found this code in arcscripts but cannot get it to function.

Dim valI as integer Dim valB as string Dim x as integer valI = [fieldName] for x = 7 to 0 step -1 if valI >= 2^x then valB = valB & 1 valI = valI - 2^x else valB = valB & 0 end if Next valB = valB & "00000000"

fieldName = valB

  • Just to clarify I'm looking for a field calculator expression to change the [value] to binary as shown above in the 'textbin field. This was done via an excel join.
    – user17614
    Aug 7, 2013 at 17:45

1 Answer 1


There are many threads on this issue, here are some examples

>>> bin(100)
>>> bin(4)
>>> getBin = lambda x, n: x >= 0 and str(bin(x))[2:].zfill(n) or "-" + str(bin(x))[3:].zfill
>>> getBin(4,8)
  • 1
    To expand on this: using the field calculator, set the parser to Python, then use the expression bin(!VALUE!)[2:].zfill(8), where VALUE is the name of the field you want to convert. Aug 7, 2013 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy