help with binary numbers and logics

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ravnosense
Posts: 1
Joined: 18 Jul 2013 20:51

help with binary numbers and logics

#1 Post by ravnosense » 18 Jul 2013 20:57

Hello,
I want a batch code to output things like this:
0000
0001
0010
0011
0100
and so on...

I would appreciate any help,
I already have a code for testing some basic binary logics,
but still haven't found a code to give me the binary enters...

regards,

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: help with binary numbers and logics

#2 Post by Aacini » 19 Jul 2013 00:10

If you want to convert a decimal number to binary, then this code do the trick:

Code: Select all

@echo off
setlocal EnableDelayedExpansion
set /P "decimal=Enter decimal number: "
set binary=
for /L %%i in (1,1,32) do (
   set /A "bit=decimal&1, decimal>>=1"
   set binary=!bit!!binary!
)
echo The binary equivalent is: %binary%


Antonio

Post Reply