Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2005.11.06;
Скачать: CL | DM;

Вниз

Как преобразовать число к бОльшему квадрату двойки ?   Найти похожие ветки 

 
X-Fi   (2005-10-13 02:28) [0]

Там 12 в 16, 50 в 64, 1000 в 1024 и т. д.

Просто ничего кроме кучи условий или цикла в голову не приходит. А может существует какая простая формула, чтобы быстро работала ?


 
MBo ©   (2005-10-13 07:27) [1]

function RoundUpPower2(N: Integer): Integer;
begin
 Dec(N);
 N := N or (N shr 1);
 N := N or (N shr 2);
 N := N or (N shr 4);
 N := N or (N shr 8);
 N := N or (N shr 16);
 Result := N + 1;
end;


 
Digitman ©   (2005-10-13 08:54) [2]

function RoundUpPower2(const Value: DWord): Int64;
asm
 sub esp, 8
 bsr edx, eax
 mov eax, 0
 mov [esp], eax
 mov [esp+4], eax
 jz  @@exit
 inc edx
 bts [esp], edx
@@exit:
 mov eax, [esp]
 mov edx, [esp+4]
 add esp, 8
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
 showmessage(inttostr(RoundUpPower2(12)));
 showmessage(inttostr(RoundUpPower2(50)));
 showmessage(inttostr(RoundUpPower2(1000)));
end;



Страницы: 1 вся ветка

Текущий архив: 2005.11.06;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.052 c
2-1129227203
softmaster
2005-10-13 22:13
2005.11.06
Проблема в fiblpus


14-1129187760
TButton
2005-10-13 11:16
2005.11.06
Я вспомнил!!!


14-1129345447
Brother
2005-10-15 07:04
2005.11.06
На тему эмуляторов и пр.


3-1127459903
Леди
2005-09-23 11:18
2005.11.06
Что за ошибка? Command contains unrecognized phrase/keyword.


3-1127308032
Juice
2005-09-21 17:07
2005.11.06
Модификация через сетку табл. без ключей