比如 int 转 byte之类的。
当然也可以直接运算,比如对于整形来说左移1大约就是*2,右移1大约就是/2。
例如参见BinaryWriter(下面的函数是扩展了,去掉Big就是原有的,它里面的实现就有移位):
protected override void OnWriteToBuffer(BinaryWriter writer)
{
writer.WriterBig(Length);
writer.WriterBig(Number);
writer.WriterBig((ushort)Catelog);
writer.WriterBig(SessionId);
writer.WriterBig(Version.Buffer);
writer.WriterBig((byte)EncryptOpition);
writer.WriterBig(KeyForCommonEncript);
}
谢了,
我是想:大多数算法,都是对10进制数字的操作, 利用二进制5种运算特性,或许可以给算法开辟另一番蓝海。。
@Coca-code: 呵呵。有想象力很好,你那么有兴趣应该好好看看计算机原理,看看布尔数学。
@花飘水流兮: 恩师
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" > <!-- 应该在此定义资源字典条目。 --> <BitmapImage x:Key="LogoImage" UriSource="/WpfApp1;component/Image/Logo/Logo.png" /> <!-- Close Resources。 --> <BitmapImage x:Key="CloseNormalImage" UriSource="/WpfApp1;component/Image/Close/Close-Normal.png" /> <BitmapImage x:Key="CloseIsMouseOverImage" UriSource="/WpfApp1;component/Image/Maximize/Maximize-IsMouseOver.png" /> <BitmapImage x:Key="CloseIsPressedImage" UriSource="/WpfApp1;component/Image/Close/Close-IsPressed.png" /> <!-- Minimize Resources。 --> <BitmapImage x:Key="MinimizeNormalImage" UriSource="/WpfApp1;component/Image/Maximize/Minimize-Normal.png" /> <BitmapImage x:Key="MinimizeIsMouseOverImage" UriSource="/WpfApp1;component/Image/Maximize/Minimize-IsMouseOver.png" /> <BitmapImage x:Key="MinimizeIsPressedImage" UriSource="/WpfApp1;component/Image/Minimize/Minimize-IsPressed.png" /> <!-- Maximise Resources。 --> <BitmapImage x:Key="MaximizeNormalImage" UriSource="/WpfApp1;component/Image/Maximize/Maximize-Normal.png" /> <BitmapImage x:Key="MaximizeIsMouseOverImage" UriSource="/WpfApp1;component/Image/Maximize/Maximize-IsMouseOver.png" /> <BitmapImage x:Key="MaximizeIsPressedImage" UriSource="/WpfApp1;component/Image/Maximize/Maximize-IsPressed.png" /> <LinearGradientBrush x:Key="ButtonCommonBrush" StartPoint="0.5,0" EndPoint="0.5,1"> <GradientStop Offset="0" Color="#FFC7E4FE" /> <GradientStop Offset="0.5" Color="#FFC7E4FE" /> <GradientStop Offset="0.5" Color="#FFA2D8F8" /> <GradientStop Offset="0.55" Color="#FFA2D8F8" /> <GradientStop Offset="0.55" Color="#FF8DD5F6" /> <GradientStop Offset="1" Color="#FF8DD5F6" /> </LinearGradientBrush> <LinearGradientBrush x:Key="ButtonPressedBrush" StartPoint="0.5,0" EndPoint="0.5,1"> <GradientStop Offset="0" Color="#FF8DC7FC" /> <GradientStop Offset="0.5" Color="#FF8DC7FC" /> <GradientStop Offset="0.5" Color="#FF6CB1F1" /> <GradientStop Offset="0.55" Color="#FF6CB1F1" /> <GradientStop Offset="0.55" Color="#FF54A4EA" /> <GradientStop Offset="1" Color="#FF54A4EA" /> </LinearGradientBrush> <LinearGradientBrush x:Key="ButtonNormalBackground" StartPoint="0,0" EndPoint="0,1"> <GradientStop Offset="0" Color="#FFE5E5E5" /> <GradientStop Offset="0.5" Color="#EBEBEB" /> <GradientStop Offset="0.5" Color="#FFCACACA" /> <GradientStop Offset="1" Color="DarkGray" /> </LinearGradientBrush> <SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070" /> <SolidColorBrush x:Key="ButtonMouseOverBorder" Color="#FF5FAFEE" /> <SolidColorBrush x:Key="ButtonPressedBorderBrush" Color="#FF7BCB48" /> <Style TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid> <Border x:Name="border" Background="{DynamicResource ButtonNormalBackground}" BorderBrush="{DynamicResource ButtonNormalBorder}" BorderThickness="1" CornerRadius="6" /> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsFocused" Value="True" /> <Trigger Property="IsDefaulted" Value="True" /> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="border" Property="Background" Value="{DynamicResource ButtonCommonBrush}" /> <Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource ButtonMouseOverBorder}" /> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="border" Property="Background" Value="{DynamicResource ButtonPressedBrush}" /> <Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource ButtonPressedBorderBrush}" /> </Trigger> <Trigger Property="IsEnabled" Value="False" /> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="TabControlButtonStyle" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid> <Border x:Name="border" Background="{DynamicResource ButtonNormalBackground}" BorderBrush="{DynamicResource ButtonNormalBorder}" BorderThickness="1" CornerRadius="6" /> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsFocused" Value="True" /> <Trigger Property="IsDefaulted" Value="True" /> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="border" Property="Background" Value="{DynamicResource ButtonCommonBrush}" /> <Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource ButtonMouseOverBorder}" /> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="border" Property="Background" Value="{DynamicResource ButtonPressedBrush}" /> <Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource ButtonPressedBorderBrush}" /> </Trigger> <Trigger Property="IsEnabled" Value="False" /> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="CloseButtonStyle" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Image Name="image" Source="{StaticResource CloseNormalImage}" /> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="image" Property="Source" Value="{StaticResource CloseIsMouseOverImage}" /> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="image" Property="Source" Value="{StaticResource CloseIsPressedImage}" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="MinimizeButtonStyle" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Image Name="image" Source="{StaticResource MinimizeNormalImage}" /> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="image" Property="Source" Value="{StaticResource MinimizeIsMouseOverImage}" /> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="image" Property="Source" Value="{StaticResource MinimizeIsPressedImage}" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="MaximizeButtonStyle" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Image Name="image" Source="{StaticResource MaximizeNormalImage}" /> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="image" Property="Source" Value="{StaticResource MaximizeIsMouseOverImage}" /> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="image" Property="Source" Value="{StaticResource MaximizeIsPressedImage}" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>