zoukankan
html css js c++ java
C#算法求2进制的问题
Code
1
using
System;
2
using
System.Collections.Generic;
3
using
System.Linq;
4
using
System.Text;
5
6
namespace
NumnerOutput
7
{
8
class
Program
9
{
10
static
void
Main(
string
[] args)
11
{
12
List
<
double
>
d
=
Get2PowArray(
10
);
13
foreach
(
double
dd
in
d)
14
{
15
Console.WriteLine(dd.ToString());
16
}
17
Console.ReadKey();
18
}
19
public
static
double
pow2(
double
n)
20
{
21
double
i
=
0
;
22
23
while
(Math.Pow(
2
, i)
<
n)
24
{
25
i
++
;
26
}
27
if
(Math.Pow(
2
, i)
>
n)
28
return
--
i;
29
else
30
return
i;
31
}
32
public
static
List
<
double
>
Get2PowArray(
double
n)
33
{
34
double
temp
=
n;
35
List
<
double
>
arrayList
=
new
List
<
double
>
();
36
while
(temp
>=
1
)
37
{
38
double
maxIndex
=
pow2(temp);
39
temp
-=
Math.Pow(
2
,maxIndex);
40
arrayList.Add(Math.Pow(
2
,maxIndex));
41
}
42
return
arrayList;
43
}
44
45
}
46
}
47
查看全文
相关阅读:
Object doesn't support property or method 'flat'
yapi的部署
mongoDB 安装
排序
直播原理
文件怎么都删不掉,压缩,命令行都不行
computed和watch
docker安装
跨域问题的解决方案
一次普通的http请求
原文地址:https://www.cnblogs.com/binlyzhuo/p/1543612.html
最新文章
哪个包
openstack install
centon7.2 mini install
centos 网卡名修改
LINUX3
input框带图片的写法
利用psd文件写出html css结构的流程
HTML <form> 标签的 enctype 属性
一万小时定律
今天是2018年6月2号,重新确定目标,坚定不移
热门文章
一些 iOS 常用的第三方库
iOS常用第三方类库 Xcode插件
iOS之单例模式初探
IOS UITableView删除功能
IOS UITableView拖动排序功能
移动端前端开发调试
iOS下拉刷新和上拉刷新
iOS定位和位置信息获取
反选,全选,删除按钮的实现
网络总结
Copyright © 2011-2022 走看看