zoukankan      html  css  js  c++  java
  • 位运算Pascal相关函数/过程

    Function Getlen(P:longint):longint;
    var
     i:longint;
      begin
      getlen:=0;
      for i:=1 to 31 do
        begin
        if p and 1=1 then getlen:=i;
        p:=p shr 1;
      end;
    end;
    
    Function GetBit(Num,bit:longint):boolean;
      begin
      if (num and (1 shl(bit-1)))=0 then exit(false) else exit(true);
    end;
    
    Procedure changeBit(var num:longint;bit:longint;opt:boolean);
      begin
      if opt then
        num:=num or (1 shl (bit-1))
      else
        num:=num and not (1 shl (bit-1));
    end;
    
    Function getblock(num:longint;start,len:longint):longint;
    var
     i,tmp:longint;
      begin
      tmp:=0;
      for i:=1 to len do
        tmp:=tmp or (1 shl (i-1));
      Getblock:=(num and (tmp shl (start-1))) shr (start-1);
    end;
    
    Procedure changeBlock(var num:longint;start,opt:longint);
    var
     len,tmp,i:longint;
      begin
      len:=getlen(opt);
      tmp:=0;
      for i:=1 to len do
        begin
        tmp:=tmp or 1;
        tmp:=tmp shl 1;
      end;
      tmp:=not (tmp shl (start-1));
      num:=num and tmp;
      num:=num or (opt shl (start-1));
    end;      
    
  • 相关阅读:
    用Python实现多核心并行计算
    Sublime Text 中文乱码
    Python_pickle
    New blog
    git Bash常用命令
    用TTS实现文本转语音
    bc#54 div2
    用Python制作新浪微博爬虫
    hdu5000 背包dp
    mac下配置Qt for Android+iOS
  • 原文地址:https://www.cnblogs.com/htfy/p/2412251.html
Copyright © 2011-2022 走看看