declare @ch nchar(10),@n int,@a int set @n=20 set @ch='' print cast(@n as varchar(5))+'的二进制为:' while @n<>0 begin set @a=@n%2 set @n=@n/2 set @ch=char(48+@a)+@ch end print @ch
结果为:
20的二进制为:
10100
原文地址:http://blog.csdn.net/u012110719/article/details/40922889